Home > Software engineering > VB call C calling convention of the DLL data type conversion and operation error
VB call C calling convention of the DLL data type conversion and operation error
Time:09-23
Recently in reference C language DLLS when encounter problems, because the only gave some function, met some problems, so I ask you the The function specification given 1, void * __stdcall New_Object ()//return: create a new Panel object pointer VB - Public Declare Function New_Object Lib "BS7400Ctl () As" Long statement correct? What type void * use to say? As a return value, what is the difference between function arguments? After that statement, returns a long value in the course of vb
2, the void __stdcall Delete_Object (void * pObject)//release a Panel object, pObject is above return a pointer to a Panel of VB - Public Declare Sub Delete_Object Lib "BS7400Ctl" (ByVal pObject As Long) With the above long value as a parameter, in the IDE runtime tip: a 94 error, error calling DLL convention, but not after the generated EXE error, is it?
3, the DWORD __stdcall OpenReceiver (void * pObject, TRANDATAPROC pTranFunc, LPVOID pPara) VB - Public Declare Function OpenReceiver Lib "BS7400Ctl" (ByVal pObject As Long, ByVal pTranFunc As Long, ByVal pPara As Long) As Long Parameters: pTranFunc -- the callback function; PPara - pointer to the callback function related parameters, The pPara here is what the devil? How vb statement
Please feel free to comment, and we can negotiate
CodePudding user response:
Preliminary feeling: there is nothing wrong with your 1 and 2 is, But if in the IDE, 2 will be calling convention "error", please confirm Delete_Object function prototype is as true as you say ,
In VB6, no matter what kind of "pointer", all can be expressed in Long; But when a function call, must pay attention to the function prototype to points clear: whether the value, or "reference",
"3" : what the heck on earth is that pPara, have to look at its documentation, Single from the function prototype, you use is not wrong,
But the second parameter, maybe you can be declared as: [ByRef] pTranFunc as TRANDATAPROC So, when the called function, directly TRANDATAPROC variables of type, According to your "ByVal pointer", of course, also can, just call to use VarPtr () to obtain TRANDATAPROC type the address of the variable to pass parameters,
CodePudding user response:
Dizzy, just looked at it again, only to find that "3" the second parameter is the callback function,
This callback function is a function address, can according to your statement parameters in VB6, When calling a function, is to use AddressOf take "the address of the callback handler" parameter,