Reputation: 160
I tried to use __declspec(dllexport) to export functions in my DLL, but it doesn't work. When I run GetProcAddress in main app, it always shows "The specified module could not be found".
But if I export my functions by .def file. It works very well.
Can you help me to solve this problem. I want to use __declspec(dllexport) instead of the .def file.
Thank you very much. (I'm using Visual C++ 2005, MFC)
Upvotes: 2
Views: 5863
Reputation: 942267
The specified module could not be found
That's the wrong error message, you will only get that when LoadLibrary fails. Typically because you are using the wrong file name. GetProcAddress() fails with error 127, "The specified procedure could not be found".
Assuming it is actually the exported function name, you do not have a lot of options to rename the function with __declspec(dllexport). You only have extern "C"
to suppress C++ name mangling. The exported name is still going to have a underscore before its name, @n after its name if it was declared __stdcall. Exporting completely undecorated is only possible in 64-bit code or by using a .def file.
Use dumpbin.exe /exports on the DLL to see actual names. You'll get a better dump if you delete the .pdb file first. Depends.exe is fine too.
Upvotes: 3
Reputation: 44201
I expect you're not looking for the right name when using GetProcAddress
. Have you used dumpbin or Dependency Walker to verify the name of the exported function yet?
Upvotes: 0