loading and initializing MarkEzd.dll in C#

Viewed 297

I am trying to load "MarkEzd.dll" in my c# project. For get access to the DLL file, I called it as:

static class A
{
    [DllImport("MarkEzd.dll", EntryPoint = "lmc1_Initial2", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
    public static extern int Initialize(string PathName, bool TestMode)
}

I followed the structure supposed by "Bkjames" in this post: Loading a C++ DLL in C#

Then I wrote this line:

A.Initialize(@"The path of MarkEzd.dll", true);

but I got this error message: Unable to load DLL `MarkEzd.dll': this specified module could not be found. [Exception from HRESULT: 0x8007007E)

Does anybody have any idea? I am in Debug mode. and I see that the MarkEzd.dll is in the debug folder.

1 Answers

Try this

[DllImport("MarkEzd.dll", EntryPoint = "lmc1_Initial2", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int lmc1_Initial2(string strEzCadPath, int bTestMode, IntPtr hOwenWnd);

And calling

int ErrorCode = lmc1_Initial2(Application.StartupPath, 0, Handle);  

And you can define errors as

#define LMC1_ERR_SUCCESS 0 // Success
#define LMC1_ERR_EZCADRUN 1 // Find EZCAD running
#define LMC1_ERR_NOFINDCFGFILE 2 // Can not find EZCAD.CFG
#define LMC1_ERR_FAILEDOPEN 3 // Open LMC1 board failed
#define LMC1_ERR_NODEVICE 4 // Can not find valid lmc1 device
#define LMC1_ERR_HARDVER 5 // L mc1 s version is error.
#define LMC1_ERR_DEVCFG 6 // Can not find configuration files
#define LMC1_ERR_STOPSIGNAL 7 // A larm signal
#define LMC1_ERR_USERSTOP 8 // User stops
#define LMC1_ERR_UNKNOW 9 // Unknown error
#define LMC1_ERR_OUTTIME 10 // Overtime
#define LMC1_ERR_NOINITIAL 11 // Un-initialized
#define LMC1_ERR_READFILE 12 // Read file error
#define LMC1_ERR_OWENWNDNULL 13 // Window handle is NULL
#define LMC1_ERR_NOFINDFONT 14 // Can not find designated font
#define LMC1_ERR_PENNO 15 // Wrong pen number
#define LMC1_ERR_NOTTEXT 16 // Object is not text
#define LMC1_ERR_SAVEFILE 17 // Save file failed
#define LMC1_ERR_NOFINDENT 18 // Can not find designated object
#define LMC1_ERR_STATUE 19 // Can not run the operation in
Related