troubleshooting Question

pragma comment EXPORT confusion!

Avatar of mrwad99
mrwad99Flag for United Kingdom of Great Britain and Northern Ireland asked on
4 Comments1 Solution3114 ViewsLast Modified:
Ah hello.

I recently built a DLL that needed to be used via GetProcAddress.  I discovered that due to name mangling, this function call was failing, so began to create a .DEF file that would declare my function to be exported.  However, I realised that I had seen this done via the

#pragma comment(linker, "/EXPORT"

I have the following code:

// stdafx.h

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>

// ExportedFunction.cpp

#include "StdAfx.h"

#pragma comment(linker, "/EXPORT:ExportedFunction2=_ExportedFunction@4")

typedef int MSIHANDLE;

extern "C" UINT __stdcall ExportedFunction( UINT )
      return 0;

// stdafx.cpp


I build to a Win32 DLL.

My question is about the arguments to the #pragma comment code.  Obviously the first part "ExportedFunction" is what I want my function to be accessed via using GetProcAddresss.  Indeed, when I load my DLL in dependency viewer, I see one entry:  ExportedFunction2.

The second part is confusing.  The code as-is will compile and link.  If I remove the _ from the second part, it fails with

unresolved external symbol ExportedFunction@4      MYDLL_.exp

If I change @4 to another number, it fails with the same error.  If I remove the parameter from the function, leaving everything else as-is, it also fails with this error.  

Can someone please tell me What is going on here, and if there is any documentation I can read so I can learn about what these arguments mean?

PS I know I can also achieve this via __declspec etc, but I would like to learn how to export in this manner too.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros