K720_Dll Convert DLL C# for C++

Viewed 47

I want to use DLL for C++ in C#

HANDLE __stdcall K720_CommOpenWithBaud(char *Port, unsigned int _data);
int __stdcall K720_SendCmd(HANDLE ComHandle, unsigned char MacAddr, char *p_Cmd, int CmdLen, char *RecordInfo);

How can I change this code for C#?

[DllImport(@"K720_Dll.dll")]
public static extern int K720_CommOpenWithBaud(string Port, int _data);
[DllImport(@".K720_Dll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int K720_SendCmd(int ComHandle, byte MacAddr, string cmd, int cmdLen, StringBuilder RecordInfo);

I wrote this in C#

And the data used in the K720_SendCmd function is

in ComHandle open comhandle
in MacAddr machine address, effective val
in *p_Cmd Save command character string
in CmdLen Order character length
out RecrodInfo Save communication record of this command

When I call a function, the device works, but the program ends immediately.

    public override int OpenDevice()
    {
        int iReturn;
        iReturn = K750.K720_CommOpenWithBaud(mDevicePort, mBaudrate);
        ComHandle = iReturn;
        return iReturn;
    }

    public override int InitDevice()
    {
        int iReturn;
        string recordInfo = "";
        StringBuilder RecordInfo = new StringBuilder(recordInfo);
        iReturn = K750.K720_SendCmd(ComHandle, MacAddr, "RS", 2, RecordInfo);
        return iReturn;
    }

I don't know why the program shuts down

0 Answers
Related