• Advertisement
Sign in to follow this  

Exporting Assembly Functions from C++ DLL

This topic is 3940 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[Microsoft Visual Studio 2003 Cpp / MASM32] I have a set of functions written in assembly that I want to be part of a DLL I'm building in Cpp. I have the assembly files part of the Cpp project, and they use a Custom Build Step to assemble with MASM32 (ml.exe). The functions work fine when called in the DLLs internal functions, but I recieve a LNK2019 (unresolved external symbol) error when I try to call the functions from an application using the DLL. error LNK2019: unresolved external symbol _AssemblyFunction@0 referenced in function "public: virtual void __thiscall Game::Update(void)" (?Update@Game@@UAEXXZ)
//In one of the DLL headers...

extern "C" 
{
	void __stdcall AssemblyFunction(void);
} 

I also tried
//In one of the DLL headers...

extern "C" 
{
	__declspec(dllexport)/*__declspec(dllimport)*/ void __stdcall AssemblyFunction(void);
} 

Still, the AssemblyFunction wasn't exported in the .lib... I figured I would try a .def file export method
; Project Definition File

LIBRARY	MyDLL
EXPORTS AssemblyFunction

When I searched through the .lib file I then found references to "_AssemblyFunction@0" and "__imp__AssemblyFunction@0" so I thought the problem was solved, but no, the same error occurs. I don't know if there's a project setting, linking problem... exporting problem... assembly problem...I have tried pretty much everything. I've done a lot of research on this, but I can't find anything with particular examples for this type of setup.

Share this post


Link to post
Share on other sites
Advertisement
Okay, problem solved. Though I had Cleaned/Rebuilt/Relinked etc... both the DLL project and the Application project numerous times I had not tried one thing: switching to Debug Configuration, building, and then switching back to Release Configuration and building. I didn't know this would work, and I wasn't even trying to fix the problem, but for some reason the Assembly functions got exported correctly by the .def file when I did this. I created a new assembly function, got the same error in Release mode, switched to debug, built, switched to release built, no error. I don't know if this is a bug, or if building in a different mode cleans something that doesn't occur in a Rebuild. Very strange either way, but I'm just happy that its working now...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement