Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中调用Delphi DLL“;试图读取或写入受保护的内存&引用;错误_C#_Delphi_Dll_Dllimport - Fatal编程技术网

C# 在c中调用Delphi DLL“;试图读取或写入受保护的内存&引用;错误

C# 在c中调用Delphi DLL“;试图读取或写入受保护的内存&引用;错误,c#,delphi,dll,dllimport,C#,Delphi,Dll,Dllimport,我正在尝试导入delphi dll并使用其方法 以下是德尔菲法签名: function CALinkEncode(SubscriberID, MailshotID, LinkID: DWORD; sCode: PWideChar): HRESULT; stdcall; 下面是导入dll并使用函数的c代码 [DllImport(@"Decoder.dll", CharSet = CharSet.Ansi)] static extern string CALinkEncode(

我正在尝试导入delphi dll并使用其方法

以下是德尔菲法签名:

function CALinkEncode(SubscriberID, MailshotID, LinkID: DWORD; sCode: PWideChar): HRESULT; stdcall; 
下面是导入dll并使用函数的c代码

    [DllImport(@"Decoder.dll", CharSet = CharSet.Ansi)]
    static extern string CALinkEncode(
        int SubscriberID,
        int MailshotID,
        int LinkID
    );

    public static string CALinkDecodeString(int cas, int cam, int cal)
    {
        string retvalptr = CALinkEncode(cas, cam, cal);

        return retvalptr;
    }

请提供帮助。

您缺少一个参数,返回类型错误,字符集错误。应该是:

[DllImport(@"Decoder.dll", CharSet = CharSet.Unicode)]
static extern uint CALinkEncode(
     uint SubscriberID,
     uint MailshotID,
     uint LinkID,
     string sCode
 );
我假设字符串参数是一个输入参数。如果不是,则需要将其声明为StringBuilder,并传递一个具有足够输出缓冲区容量的StringBuilder实例


.

您缺少一个参数,返回类型错误,字符集错误。应该是:

[DllImport(@"Decoder.dll", CharSet = CharSet.Unicode)]
static extern uint CALinkEncode(
     uint SubscriberID,
     uint MailshotID,
     uint LinkID,
     string sCode
 );
我假设字符串参数是一个输入参数。如果不是,则需要将其声明为StringBuilder,并传递一个具有足够输出缓冲区容量的StringBuilder实例