digitalmars.D.learn - how call a c function with stdcall?
- mzfhhhh (25/25) Mar 24 2015 for example:use vc compile on x86
- Adam D. Ruppe (1/1) Mar 24 2015 try extern(Windows) isntead of extern(C).
- mzfhhhh (9/10) Mar 24 2015 use extern(Windows) or extern(System)
- Adam D. Ruppe (7/9) Mar 24 2015 You might also need to specify the .def file as the final
- mzfhhhh (9/18) Mar 24 2015 1.def file:
for example:use vc compile on x86 func.c: __declspec(dllexport) int _stdcall sub(int a,int b) { return a-b; } func.def: LIBRARY EXPORTS sub ----------------- i use "implib.exe" to create a omf format lib. ---------------- D code: import std.exception; //this is a cdecl call extern(C) int sub(int a,int b); void main() { auto c1 = sub(2,1); //when this line run,the c1 value is broken auto c2 = enforceEx!Exception(sub(1,2)); } ------------------ my question is how write D code to call the c function
Mar 24 2015
try extern(Windows) isntead of extern(C).
Mar 24 2015
On Tuesday, 24 March 2015 at 15:26:22 UTC, Adam D. Ruppe wrote:try extern(Windows) isntead of extern(C).use extern(Windows) or extern(System) the compile show the link error: Error 42: Symbol Undefined _sub 8 ---------------- dll export func name is "sub", and the dll is 3rd party,i can't change the dll code. i use "implib.exe /system func.lib func.dll" to create a func.lib. how can i link correctly?
Mar 24 2015
On Wednesday, 25 March 2015 at 00:09:33 UTC, mzfhhhh wrote:i use "implib.exe /system func.lib func.dll" to create a func.lib.You might also need to specify the .def file as the final argument to that. http://digitalmars.com/ctg/implib.html The def file can list aliases for the functions. Maybe try it without the /system flag too. I know there's a way but I don't know exactly what, I just tend to guess and check a little...
Mar 24 2015
On Wednesday, 25 March 2015 at 00:26:21 UTC, Adam D. Ruppe wrote:On Wednesday, 25 March 2015 at 00:09:33 UTC, mzfhhhh wrote:1.def file: LIBRARY "func" EXPORTS _sub 8 = sub 2.create lib implib.exe func.lib func.def ------------------------- now it works fine,thanks!i use "implib.exe /system func.lib func.dll" to create a func.lib.You might also need to specify the .def file as the final argument to that. http://digitalmars.com/ctg/implib.html The def file can list aliases for the functions. Maybe try it without the /system flag too. I know there's a way but I don't know exactly what, I just tend to guess and check a little...
Mar 24 2015