troubleshooting Question

pragma comment EXPORT confusion!

Avatar of mrwad99
mrwad99Flag for United Kingdom of Great Britain and Northern Ireland asked on
C++
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

<Empty>

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.

TIA
ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004