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,

CodePudding user response:

refer to the second floor Chen8013 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,


Thank you
Actually asked 1, 2, I don't know why things will go wrong operation, generated EXE will not, another DLL function prototypes I didn't see, this is a third party, temporarily haven't reached their developers,,, so ask here first, see if there is any other possible

3 q, I don't understand the third parameter pPara - callback function parameters related to a pointer, this is what the value
The callback function Public Sub RcvData (ByVal pObject As Long, ByVal sRcvData As String, ByVal iDataLen As Long)
End Sub

CodePudding user response:

Didn't see the function prototype is what, is this your guess parameters format?


Second, you can try to Declare the Function... As long

3 Chinese, so what to pass parameters, it is decided by the application developer, other people can "think"???????

Want to figure out how to use, one is contact related technical personnel or find relevant documentation;
Another is to look for a correct application example code,

Otherwise, you are the disassembly and analysis it "what needs to be" on earth!

CodePudding user response:

reference 4 floor Chen8013 response:
didn't see the function prototype is what, is this you guess the parameters of the format?


Second, you can try to Declare the Function... As long

3 Chinese, so what to pass parameters, it is decided by the application developer, other people can "think"???????

Want to figure out how to use, one is contact related technical personnel or find relevant documentation;
Another is to look for a correct application example code,

Otherwise, you are the disassembly and analysis it "what needs to be" on earth!


I wrote above is that they provide the function prototype (but no sample), just don't see the specific things in the DLL, and then I also don't know whether there are other cause this problem, since this way to ask you,,

Thank you, first I tried to contact their developers ask

CodePudding user response:

Don't be A language code is modified to B language code busywork,
Also don't use A language code to directly invoke B language code base, this complicated things so easy to get wrong,
Just make A, B language code of input and output is redirected to A text file, or modify A, B language code let it through text file input and output,
Can easily make A, B coordination between the two languages,
For example:
A will request data written to A file a.t xt, renamed after finish aa. TXT
B find aa. TXT, read its contents, call the corresponding function, and writes the results file b.t xt, after finish delete aa. TXT, changed its name to bb. TXT
Found A bb. TXT, read the content, after finish delete bb. TXT
Above can be replaced by any kind of A language or development environment, B can be replaced by any kind of with the development of A different language or development environment,
Unless A or B does not support to determine whether A file exists, file read and write and file name,
But who can name does not support to determine whether a file exists, file read and write and file name for the development of language or development environment?
Can put the temporary files on the RamDisk efficiency decrease wear disk,
Data structure is very complex, a text file format problems refer to a json or XML

The communication methods between the temporary text file sharing this process there are plenty of advantages, compared to other method only listed below I can think of now:
Loose coupling between process,
Can be on the same machine, process, also can cross machine, across the operating system, hardware platform, and even multinational,
, convenient debugging, and monitoring, only let the third party or artificial view the temporary text files,
Switch, convenient online service, need to delete or create the temporary text files,
, is convenient to realize distributed and load balancing,
Services to provide convenient, queue, queue is full and it is almost impossible to happen (unless the hard disk space full)
DE...

"Across different languages, machine, across the operating system, hardware platform, multinational, cross *. *" misery,
Back is "the use of Shared a plain text file information communication" of the shore!

CodePudding user response:

refer to 6th floor zhao4zhong1 response:
don't do A language code is modified to B language code busywork,
Also don't use A language code to directly invoke B language code base, this complicated things so easy to get wrong,
Just make A, B language code of input and output is redirected to A text file, or modify A, B language code let it through text file input and output,
Can easily make A, B coordination between the two languages,
For example:
A will request data written to A file a.t xt, renamed after finish aa. TXT
B find aa. TXT, read its contents, call the corresponding function, and writes the results file b.t xt, after finish delete aa. TXT, changed its name to bb. TXT
Found A bb. TXT, read the content, after finish delete bb. TXT
Above can be replaced by any kind of A language or development environment, B can be replaced by any kind of with the development of A different language or development environment,
Unless A or B does not support to determine whether A file exists, file read and write and file name,
But who can name does not support to determine whether a file exists, file read and write and file name for the development of language or development environment?
Can put the temporary files on the RamDisk efficiency decrease wear disk,
Data structure is very complex, a text file format problems refer to a json or XML

The communication methods between the temporary text file sharing this process there are plenty of advantages, compared to other method only listed below I can think of now:
Loose coupling between process,
Can be on the same machine, process, also can cross machine, across the operating system, hardware platform, and even multinational,
, convenient debugging, and monitoring, only let the third party or artificial view the temporary text files,
Switch, convenient online service, need to delete or create the temporary text files,
, is convenient to realize distributed and load balancing,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • API
  • Related