Archive: Problem with Plugin built on MinGW


Problem with Plugin built on MinGW
Hello!
I'm having an issue when creating a plugin on MinGW compiler. Keep in mind this worked fine with Borland compiler, but I prefer MinGW beacuse Borland conflicts too much with what I need to do. I made a very simple plugin so we can easily identify the problem.

The IDE I'm using is CodeBlocks by the way

Basically the problem is that when I try and compile the NSIS script, NSIS does not recognize my plugin

NSIS says : "Invalid command: test::test"

NSIS Script (relevant portion):


Section "iniz"
test::test "hi"
SectionEnd


Plugin code :


#include <windows.h>
#include <fcntl.h>
#include <cstdio>
#include <stdio.h>
#include "nsis_ansi\pluginapi.h"

#define NSISFUNC(name) void __declspec(dllexport) name(HWND hWndParent, int string_size, char* variables, stack_t** stacktop, extra_parameters* extra)
extra_parameters* ep;
HANDLE g_hInstance;
static unsigned int g_stringsize;
static stack_t **g_stacktop;
static char *g_variables;

static int __stdcall popstring(char *str)
{
stack_t *th;
if (!g_stacktop || !*g_stacktop) return 1;
th=(*g_stacktop);
lstrcpyA(str,th->text);
*g_stacktop = th->next;
GlobalFree((HGLOBAL)th);
return 0;
}

NSISFUNC(test)
{
g_stacktop = stacktop;
popstring(variables);
MessageBox(0,0,variables,0);

}

BOOL WINAPI DllMain(HANDLE hInst,
ULONG ul_reason_for_call,
LPVOID lpReserved)
{
g_hInstance = hInst;
return TRUE;
}




Generated DLL:
http://www2.zippyshare.com/v/50606317/file.html
I see the "test" export in the DLL, but I'm not exactly sure what NSIS does to identify the function in the library.

Any help you people could offer would be so hugely appreciated!

Thank you

Use dependencywalker, you will see that your exported function has a decorated name. Changing void __declspec(dllexport) to extern "C" void __declspec(dllexport) might help, if not, check your compilers manual to figure out how to export functions without the decorations or use a .def file...

Note: NSIS does not care if your plugin call is test::_test_foo_bar@8 or whatever but it looks really ugly.


Awesome Anders, adding extern "C" worked. Also if I put the entire name of the export, that worked also. But the former is much cleaner. Thanks very much!