質問

I know that there are many solutions for my problem. I have tried them all; however, I still get error.

These are original functions from DLL 'KeygenLibrary.dll' :

bool dfcDecodeMachineID(char* sEncodeMachineID, int iInLen, char* sMachineID, int& iOutLen);

bool dfcCreateLicense(char* sMachineID, int iLen, char* sLicenseFilePath);

To import this DLL, I have tried:

Way 1:

unsafe public class ImportDLL
{
    [DllImport("KeygenLibrary.dll", EntryPoint = "dfcDecodeMachineID")]
    unsafe public static extern bool dfcDecodeMachineID(char* sEncodeMachineID, int iInLen, char* sMachineID, ref int iOutLen);

    [DllImport("KeygenLibrary.dll", EntryPoint = "dfcCreateLicense")]
    unsafe public static extern bool dfcCreateLicense(char* sMachineID, int iLen, char* sLicenseFilePath);
}    

Way 2:

public class ImportDLL
{
    [DllImport("KeygenLibrary.dll", EntryPoint = "dfcDecodeMachineID")]
    public static extern bool dfcDecodeMachineID([MarshalAs(UnmanagedType.LPStr)] string sEncodeMachineID, int iInLen, [MarshalAs(UnmanagedType.LPStr)] string sMachineID, ref int iOutLen);


    [DllImport("KeygenLibrary.dll", EntryPoint = "dfcCreateLicense")]
    public static extern bool dfcCreateLicense([MarshalAs(UnmanagedType.LPStr)] string sMachineID, int iLen, [MarshalAs(UnmanagedType.LPStr)] string sLicenseFilePath);
}

However, both above ways give me error:

Unable to find an entry point named 'function name' in DLL 'KeygenLibrary.dll'.

How can I fix my problem? Thanks a lot.

役に立ちましたか?

解決

SUGGESTION:

1) Run "dumpbin" on your .dll to confirm the problem is indeed name mangling.

2) If so, try the suggestion in this link:

Entry Point Not Found Exception

a) Use undname to get the undecorated name

b) Set EntryPointy == the mangled name

c) Set CallingConvention = CallingConvention.Cdecl

d) Use the unmangled name and signature for your C# method signature

See also this link:

http://bytes.com/topic/c-sharp/answers/428504-c-program-calling-c-dll

Laurent.... You can call the function using the mangled name as in:

To call a function using its fully decorated name "?fnWin32Test2@@YAJXZ" as

"Win32Test2" you can specify the static entry point as "?fnWin32Test2@@YAJXY":

[DllImport("Win32Test.dll", EntryPoint= "?fnWin32Test2@@YAJXZ")]
public static extern int fnWin32Test2();

And call it as:

System.Console.WriteLine(fnWin32Test2());

To look at the undecorated name use the undname tool as in:

`undname ?fnWin32Test@@3HA`

This converts the decorated name to "long fnWin32Test".

Regards, Jeff

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top