Having this declaration in the header:
__declspec(dllexport) int fnunmanaged(void);
__declspec(dllexport) int fnunmanaged(int);
You could use dumpbin.exe to get the exact name of the function:
dumpbin.exe /exports unmanaged.dll
Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file unmanaged.dll
File Type: DLL
Section contains the following exports for unmanaged.dll
00000000 characteristics
4B0546C3 time date stamp Thu Nov 19 14:23:15 2009
0.00 version
1 ordinal base
2 number of functions
2 number of names
ordinal hint RVA name
1 0 0001106E ?fnunmanaged@@YAHH@Z = @ILT+105(?fnunmanaged@@YAHH@Z)
2 1 00011159 ?fnunmanaged@@YAHXZ = @ILT+340(?fnunmanaged@@YAHXZ)
Summary
1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
4000 .text
10000 .textbss
And use this name when declaring the function:
[DllImport(@"D:\work\unmanaged.dll",
EntryPoint = "?fnunmanaged@@YAHH@Z",
ExactSpelling = true)]
static extern int fnunmanaged();
[DllImport(@"D:\work\unmanaged.dll",
EntryPoint = "?fnunmanaged@@YAHXZ",
ExactSpelling = true)]
static extern int fnunmanaged(int a);
Another alternative is to use a module definition file:
LIBRARY "unmanaged"
EXPORTS
fn1=?fnunmanaged@@YAHH@Z
fn2=?fnunmanaged@@YAHXZ
In this case you no longer need to use __declspec(dllexport)
and your header file might look like this:
int fnunmanaged(void);
int fnunmanaged(int);
And finally import them:
[DllImport(@"D:\work\unmanaged.dll")]
static extern int fn1();
[DllImport(@"D:\work\unmanaged.dll")]
static extern int fn2(int a);