I use DllImport like this:
[DllImport("C:\\Program Files\\SPF\\SpfIIDll.dll",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi,
EntryPoint = "InitSpfII",
ExactSpelling = true)]
static extern unsafe int InitSpfII(char* cSpfCfg, char* cHardwareCfg);CharSet = CharSet.Ansi,
EntryPoint = "InitSpfII",
ExactSpelling = true)]
When I call the function, I do it to allow a char* by doing this:
fixed (char* spfcfgpath = spfpath.ToCharArray())
{
{
fixed (char* hardwarecfgpath = hardwarepath.ToCharArray())
{
{
initValue = InitSpfII(spfcfgpath, hardwarecfgpath);
}}
I know that the function exists and I have the header file with the listings of functions:
extern "C" int __declspec(IMOREX1) InitSpfII(char* cSpfCfg, char* cHardwareCfg);
// Initialized comm port and driver. This function has to be called before any other function in this dll
// cSpfCfg: config filename, usually "SpfII.cfg"
// cHardwareCfg: hardware config file, usually "Hardware.cfg"
// return value: 0 OK. Error otherwise
I don't know what else to do. I've been working on this for weeks with no result. I would appreciate any and all help. I don't want to abandon C#, I like it a lot.

Calling C/C++ DLL function Entry Point Error
BHOGuy
[DllImport("C:\\Program Files\\SPF\\SpfIIDll.dll",
CharSet = CharSet.Ansi,
EntryPoint = "_InitSpfII",
ExactSpelling = true)]
That did the trick.
Stubey
Jazz4sale
The function may be exported with a mangled name. Use a tool like Dumpbin.exe to check the export names.
BTW, a char in C# isn't the same as a char in C++. If you change the parameter types to string instead of char* it should work better, plus you don't need the unsafe code block.