Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessViolationException when calling C function from dll on C#
    primarykey
    data
    text
    <p>I'm trying to use PInvoke in order to call an unmanaged function from a C dll. Due to the fact that the source of the dll can't be released to developers, some of them have called the function in Delphi using the following declaration. We use SAT.dll with a CDECL calling convention.</p> <pre class="lang-pascal prettyprint-override"><code>function AssociarAssinatura( numeroSessao : Longint; codigoDeAtivacao: PChar; CNPJvalue : PChar; assinaturaCNPJs : PChar ) : PChar ; cdecl; External 'SAT.DLL'; </code></pre> <p>Based on that structure, I made the following Console Application in C# in order to test the same function from the same DLL. I made some research and found out that the equivalent to Longint in delphi is int in C# and the equivalent of PChar is a pointer to a string (But I used C#'s string).</p> <pre class="lang-cs prettyprint-override"><code>class Program { [DllImport("SAT.dll", CallingConvention = CallingConvention.Cdecl)] private static extern string AssociarAssinatura(int numeroSessao, string codigoDeAtivacao, string CNPJvalue, string assinaturaCNPJs); static void Main(string[] args) { Console.WriteLine("Comienza"); int numeroSessao = 111111; string codigoDeAtivacao = "123123123"; string cnpJvalue = "2222222222222211111111111111"; string assinaturaCnpJs = "lrafwegmqcgvpzpbdmcmcgdvf"; string resposta = AssociarAssinatura(numeroSessao, codigoDeAtivacao, cnpJvalue, assinaturaCnpJs); Console.WriteLine(resposta); } } </code></pre> <p>When I call the function, an AccesViolationException is thrown. The code of AssociarAssinatura has some inner prints that show that the code from the function is indeed running well. Due to this I guess the problem is related when the function is returning it's value. My best guess is that somehow I'm having issues with the calling convention. Any thoughts?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload