Hi,
I have software which have to read data using dll writen in C. This
library has method which has header like this:
int fnGetDescription(int allwaysOpen, char *itemNumber, char *desc, char
*price, char *priceUnit, char *tempName, char *user1, char *user2, char
*user3);
allwaysOpean is 0 for every call. itemNumber is article code and other
parameters are returned data about article with itemCode (article
description, article price, etc.).
I wrote application in Borlan C++ and everything work fine. Below is
sample app in BC:
typedef int (*fnGetDescription)(int allwaysOpen, char *itemNumber, char
*desc, char *price, char *priceUnit, char *tempName, char *user1, char
*user2, char *user3);
typedef int (*fnOpenConnect)(char *sMsgQueue, char *sFileName);
typedef int (*fnReadConnfiguration)(char *workDir);
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE hInst;
fnGetDescription get;
fnOpenConnect open;
fnReadConnfiguration read;
int odp;
char sDesc[170] = { 0 };
char sPrice[90] = { 0 };
char sPricePerUnit[90] = { 0 };
char sTemplateName[90] = { 0 };
char sUser1[200] = { 0 };
char sUser2[200] = { 0 };
char sUser3[200] = { 0 };
hInst = LoadLibrary("Iss400.dll");
if(hInst != NULL)
{
read = (fnReadConnfiguration)GetProcAddress(hInst,
"fnReadConnfiguration");
open = (fnOpenConnect)GetProcAddress(hInst, "fnOpenConnect");
get = (fnGetDescription)GetProcAddress(hInst, "fnGetDescription");
if(read != NULL)
{
odp = read("c:\\PriceAnyWhere\\");
if(odp == 0)
{
if(open !=NULL)
{
odp = open("ADXLXCCN",
"C:\\PriceAnywhere\\towary.txt");
if(odp == 0)
{
if(get != NULL)
{
odp = get(0, "some code to check", sDesc,
sPrice, sPricePerUnit, sTemplateName, sUser1, sUser2, sUser3);
if(odp == 0)
{
// In this point I get properly data. I mean in parameter sUser1 I
get some string (not empty string).
}
....
Now I need to call this methods in the same way from C# code. I prepare
dllimports like this:
[DllImport(@"C:\PriceAnyWhere\Iss400.dll", CharSet = CharSet.Ansi)]
public static extern int fnReadConnfiguration(string WorkDirectory);
[DllImport(@"C:\PriceAnyWhere\Iss400.dll", CharSet = CharSet.Ansi)]
public static extern int fnOpenConnect(string Queue, string FileName);
[DllImport(@"C:\PriceAnyWhere\Iss400.dll", CharSet = CharSet.Ansi)]
public static extern int fnGetDescription(int openAlways, string EAN,
System.Text.StringBuilder desc, System.Text.StringBuilder price,
System.Text.StringBuilder unitPrice, System.Text.StringBuilder tempName,
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder user1,
System.Text.StringBuilder user2, System.Text.StringBuilder user3);
And call like this:
System.Text.StringBuilder sDesc = new System.Text.StringBuilder("",170);
System.Text.StringBuilder sPrice = new System.Text.StringBuilder("",90);
System.Text.StringBuilder sPricePerUnit = new
System.Text.StringBuilder("", 90);
System.Text.StringBuilder sTemplateName = new
System.Text.StringBuilder("", 90);
System.Text.StringBuilder sUser1 = new System.Text.StringBuilder("", 200);
System.Text.StringBuilder sUser2 = new System.Text.StringBuilder("", 200);
System.Text.StringBuilder sUser3 = new System.Text.StringBuilder("", 200);
string resp = "";
if(fnReadConnfiguration(System.IO.Path.GetDirector yName(@"C:\PriceAnyWhere\"))==0)
{
if(fnOpenConnect("ADXLXCCN", @"C:\PriceAnyWhere\towary.txt")==0)
{
if(fnGetDescription(0, "the same code like in BC code", sDesc, sPrice,
sPricePerUnit, sTemplateName, sUser1, sUser2, sUser3)==0)
{
// Point A - Comment below
}
}
}
In point A I get data but not all. parameters sDesc and SPrice are
returned correctly but sUser1 not. I get empty string. The others
parameters are not impotant for me.
What can be wrong? What can I change to get sUser1 parameter?
--
Best regards,
Klaudiusz Bryja