1
I have a DLL (gbasmsb_library.dll) provided by Farmácia Popular responsible for returning some functions for interaction with this environment.
I think it is a DLL written in C, I need to consume this DLL in VB6 OR C#.
In the Programmer’s guide programmer have the following information for using the DLL:
1:
Syntax:
const char* IdentificaEstacao();
Return value: A string containing the machine’s DNA.
2:
Syntax:
const char* PegaSolicitacao(
const char* CNPJ,
const char* CPF,
const char* CRM,
const char* UF_CRM,
const char* DT_EMISSAO );
A string that will be used to validate the request by generating the machine.
In VB6 managed to consume the first function (1), while the second returns error:
49 Bad DLL Calling Convention
Code VB6:
Private Declare Function PegaSolicitacao Lib "c:\temp\gbasmsb_library.dll" (ByRef CNPJ As String, ByRef CPF As String, ByRef CRM As String, ByRef UF_CRM As String, ByRef DT_EMISSAO As String) As String
Private Declare Function IdentificaEstacao Lib "c:\temp\gbasmsb_library.dll" () As String
Private Sub Form_Load()
MsgBox (IdentificaEstacao) //1 - retorno OK
Dim CNPJ As String, CPF As String, CRM As String, UF_CRM As String, DT_EMISSAO As String
Dim resp As String
CNPJ = "98352942000133"
CPF = "72794534491"
CRM = "7347"
UF_CRM = "AM"
DT_EMISSAO = "01/01/1991"
resp = PegaSolicitacao(CNPJ, CPF, CRM, UF_CRM, DT_EMISSAO) //2 - ERRO
end sub
I already changed the function signature to byval, changed the parameter to array also unsuccessfully.
Code C# Unsuccessful in calling any FUNCTION.
[DllImport(@"c:\temp\gbasmsb_library.dll")]
private static extern string PegaSolicitacao(string cnpj, string cpf, string crm, string ufCrm, string dtEmissao);
[DllImport(@"c:\temp\gbasmsb_library.dll")]
private static extern string IdentificaEstacao();
private void button1_Click(object sender, EventArgs e)
{
var cnpj = "98352942000133";
var cpf = "72794534491";
var crm = "7347";
var ufCrm = "PI";
var dtEmissao = "01/01/1991";
//MessageBox.Show(PegaSolicitacao(ref cnpj, ref cnpj, ref cnpj, ref cnpj, ref cnpj));
//ERRO
MessageBox.Show(PegaSolicitacao(cnpj, cpf, crm, ufCrm, dtEmissao));
//ERRO
IdentificaEstacao();
}
Thanks for the reply @Leonardo-bosquett tried various settings but unsuccessfully.
Foi feita uma tentativa de se carregar um programa com um formato incorreto. (Exceção de HRESULT: 0x8007000B)
– rubStackOverflow
I modified the answer, your exception is probably caused because you are creating a 64-bit executable
– Leonardo Bosquett
Really killed the puzzle was ANYCPU switched to x86 and it worked! I also made some changes to return the string value, follow the code to update your answer:
[return: MarshalAs(UnmanagedType.AnsiBStr)]
public static extern string IdentificaEstacao();
Thank you @Leonard-bosquett.– rubStackOverflow
The signature of the other functions receive
string
instead ofIntPtr
@Eonardo-bosquett– rubStackOverflow