-
There are two problems that arise when C calls a COM DLL wrapper library written in C++:
1 Data type conversion issues.
2 Pointer or address parameter delivery issues.
The first is the issue of data type conversion. Because C is. .NET language, utilizing is. net, so it's actually a combination of the C++ data type. .NET.
For example, the original function of C++ is:
int __stdcall functionname(unsigned char param1, unsigned short param2)
The parameter data type is in c and must be converted to the corresponding data type. Such as:
dllimport(“ com dll path/file ”)
extern static int functionname(byte param1, ushort param2)
Because the stdcall function is called, the call method of p invoke is used. The method functionname must be declared as a static external function, i.e. with the extern static header. We can see that during the call, unsigned char becomes byte, and unsigned short becomes ushort.
After transformation, the data type of the parameter remains the same, but the declaration method must be changed. Specification of the .NET language.
-
char * to C to string
int * to refint
long to int
-
You just call, hey, whatever the original data type is, you can pass it, and what will go wrong.
-
The prototype definition of your function is char, so of course you will continue to use char.
-
Using system::string will do the trick, since you've specified charset = and clr can automatically convert ASCI strings to Unicode strings (.).net string).
-
with string. char* indicates the memory address of a character type. This string shouldn't change anything in the function.
Stringbudiler is commonly used for changing strings.
-
The & symbol is a reference type in C++, similar to ref in C, and a var keyword in Dellphi as a parameter
Switched to delphi:
function nvs_login(var lloginid:dword; const sznvsip:pchar; const szuser :
pchar; const szpwd : pchar) :boolean;
-
I feel straight string, right? or string[0] ......
Since the variables in c are all pointers, string should actually be in c++.
string*……
-
It cannot be used directly, you can pass the function argument to the corresponding function, otherwise it will not be visible in the called function. Please refer to it.
-
cannot be defined as a global variable.
-
byref fingerbuf as string
In addition, the fingerbuf parameter needs to be cached in the limb area, which must not be less than 256 304 bytes.
-
Classes are no way, structs are ok.
In fact, for DLLs, the export of classes has always been a problem. I had learned a little bit about this earlier due to the needs of the project, but I finally gave up.
Then I thought of a way.
The instance of the class is passed out through the pointer, and then a layer is encapsulated on the basis of the class, and each public function is sealed with a function, and the pointer of the created class is directly passed in the parameter table, and the corresponding method is adjusted inside the dll.
The landlord might as well try it too.
For example, the g() function returns an intptr. This pointer is the pointer to create the object in the dll, but in C it is not specifically divided into Zhang San or Wang Er.
Add the global export function add2(void*) of the function add to the dll that calls a, and then convert the pointer to the function of add2 and then adjust its add method.
It's a bit of a detour behind enemy lines.
Also, since it needs to be called in C, the DLL can also be written as managed, as long as you add runtime support. How convenient is it to add a partial to that class declaration, and then add a reference directly to use it like a dll in C? I also tried a mirror-driven one, which was sealed as a hosted dll, and it was just as easy to use.
The landlord can also think about it.
-
Landlord: How did you solve the problem?
I'm also having the same issue, char**p points to an array of pointers. It's okay to follow in the dll, but when c is called, it prompts illegal memory or something.
-
If the dll file is managed**, it can be called directly in the program by attaching it directly to the bin, and if it is an unmanaged class, it can only be used.
Use the dllimportattribute to mark a public static external method, such as.
dllimport("The name of your dll")]public static extern void test(intptr s1,intptr s2);
-
Pass a two-dimensional array (char[,] or use a pointer directly in the unsafe block.
You can also try interleaved arrays (char), which I haven't tried either.
-
It should be possible to use string directly!
Once you have SPSS open, click on the Variable View tab below. Under the Name tab of the variable view, double-click the cell to enter the text in the action line. Press enter after typing, and the following parameters will be automatically generated. >>>More
Directly via "bolean bl = true; to define a Boer type whose value is true. >>>More
We can understand f(x) from the following aspects.
First: an understanding of algebraic formulas. Every algebraic formula is essentially a function. >>>More
Variables are divided into independent, dependent, and irrelevant variables. >>>More
By definition, there is (sinx).'=lim[sin(x+ x)-sinx] ( x), where x 0, will sin(x+ x)-sinx, that is, sinxcos x+cosxsin x-sinx, since x 0, so cos x 1, thus sinxcos x+cosxsin x-sinx cosxsin x, then (sinx)'=lim(cosxsin x) x, here an important limit must be used, when x 0, lim( sin x) x=1, then (sinx)'=cosx. >>>More