-1

I have a Clarion Dll and I need to call a procedure inside of it from C# (I have access to both of the codes).

It works perfectly if I don`t try to pass any parameters to the procedure.

This is the actual Clarion code, it has nothing inside, I am using it just for testing purposes.

AtualizaEstoqueNovo_Teste PROCEDURE  (string pr)           ! Declare Procedure
    CODE

The procedure MAP declaration.

50A5C8 ATUALIZAESTOQUENOVO_TESTE@Fsb

From the C# end, I am declaring an extern void function.

[DllImport("C:\\Tests\\48\\prog\\ss007.dll", EntryPoint = "ATUALIZAESTOQUENOVO_TESTE@FSB")]
    public static extern void ATUALIZAESTOQUENOVO_TESTE(string pr);   

I am calling it like any other function

ATUALIZAESTOQUENOVO_TESTE("");

It throws me the error "Unable to find an entry point named "ATUALIZAESTOQUENOVO_TESTE@FSB""

The funny thing is that if I try to do the same thing but without using any parameters, it works.

This is how I declared the function without parameters:

[DllImport("C:\\Tests\\48\\prog\\ss007.dll", EntryPoint = "ATUALIZAESTOQUENOVO_TESTE@F")]
    public static extern void ATUALIZAESTOQUENOVO_TESTE();

I really don`t know what I am missing.

Also, the C# code is inside a Windows Service, but I think that shouldn't matter

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Either the EntryPoint has been copied to the question wrong, or you are missing th ending `@Fsb` – Neil Aug 31 '21 at 13:10
  • This depends on the calling convention of the external DLL. Check this: https://stackoverflow.com/questions/20752001/passing-strings-from-c-sharp-to-c-dll-and-back-minimal-example – Ondrej Tucny Aug 31 '21 at 13:10
  • @Neil I think I wasn`t very clear, the first C# import has the @FSB, but the second is without because I have remove the paramter from the Clarion code. Updated the question with more details about the second example. – Leonardo Dalcegio Aug 31 '21 at 13:16

1 Answers1

0

So, I found a way to make it work and you don't have to pass the "@Fsb".

const UnmanagedType MYSTRING1 = UnmanagedType.BStr; // marshaled bstring

[DllImport(@"C:\\Tests\\48\\prog\\ss007.dll", EntryPoint = "ATUALIZAESTOQUENOVO_TESTE")]
public static extern void ATUALIZAESTOQUENOVO_TESTE([MarshalAs(MYSTRING1)] string MYSTRING1);        
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83