Page 1 of 1

C# program can't find DLL

Posted: April 4th, 2017, 3:51 am
by Blobbies
I'm trying to connect a PM4 to my computer with a C# program to get some parameters like velocity and such.
The problem is that I get a error that the DLL cannot be found.
I'm using a code from the internet https://micrological.appspot.com/articl ... ojects.erg.

At the end of PM3.cs the files RPPM3DDI.dll and RPPM3Csafe.dll are imported with the help of DllImport.
These files are replaced with PM3DDICP.dll and PM3CsafeCP.dll.
This is the code:

Code: Select all

        [DllImport("PM3DDICP.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort tkcmdsetDDI_init();

        [DllImport("PM3DDICP.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort tkcmdsetDDI_discover_pm3s(
           string product_name,
           ushort starting_address,
           ref ushort num_units);

        [DllImport("PM3CsafeCP.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort tkcmdsetCSAFE_init_protocol(ushort timeout);

        [DllImport("PM3CsafeCP.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern ushort tkcmdsetCSAFE_command(
           ushort unit_address,
           ushort cmd_data_size,
           uint[] cmd_data,
           ref ushort rsp_data_size,
           uint[] rsp_data);
If I run the program I get the exception: An unhandled exception of type 'System.DllNotFoundException' occurred

I was wondering (and hoping) someone might be able to help me with this problem...

Re: C# program can't find DLL

Posted: June 3rd, 2017, 8:34 pm
by TheRocketeer
The system has to be able to find the DLLs. Do you have them in the same directory as the executable? That's the easiest way to help the system find them.