Inerop help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yuriy_zubarev

    #1

    Inerop help

    Greetings,

    I apologize for re-posting this, but I'm running out of options on my
    side.

    I've got a DLL that's not COM compatible and I'm stuck using interop
    for the first time. I got couple of simple DLL calls all right but
    cannot get the most important one to work.

    Here is documentation:

    ---

    int LoadSymbol( char*sym, void *data , int max_rec , bool
    IGNORE_HOLIDAYS = true , bool RAWDATA = true ,usr_master_def *MasterRec
    = 0);

    Returns: Number of days loaded. Negative number indicates an error.

    Parameters:

    sym - Points to the stock symbol to load.

    data - Points to an array of type Stock_Record.

    max_rec - An integer value...

    IGNORE_HOLIDAYS - Boolean value...

    RAWDATA - Boolean value...

    ---

    Here is C++ example:

    ....
    char symbol[12];
    #define MAX_RECS 10000;
    Stock_Record data[MAX_RECS];
    ....
    num = LoadSymbol( symbol , &data[0] , MAX_RECS , FALSE , TRUE , 0 );
    ....

    Here is a definition for Stock_Record struct:

    typedef struct
    {
    char MM;
    char DD;
    short YY;
    float open;
    float hi;
    float lo;
    float cl;
    long vol;
    char RS;
    float oi;

    } *LPSTOCK_RECORD , Stock_Record;

    I don't know if a definition for Master_Rec is necessary (the last
    argument for LoadSymbol function) since they just passed 0 in the
    example. Pardon my naivety if it's totally wrong assumption.

    Anyway, when I call this function (LoadSymbol) I got a positive number
    returned meaning that records have been read. The only problem - they
    have no data.

    Here is C#:

    [DllImport("read er.dll")]
    public static extern int LoadSymbol(stri ng symbol, Stock_Record[]
    records, int maxDays, bool ignoreHolidays, bool rawData, int
    masterRecord);

    (I might have screwed up with "int masterRecord" part...). The
    following is C# brother of Stock_Record:

    [StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Ansi)]
    public struct Stock_Record
    {
    public string MM;
    public string DD;
    public short YY;
    public float open;
    public float hi;
    public float lo;
    public float cl;
    public long vol;
    public string RS;
    public float OI;

    }

    And some execution code:

    ....
    Stock_Record[] records = new Stock_Record[100];
    int daysLoaded = LoadSymbol("MSF T", records, 100, false, true, 0);
    ....

    The situation here is that "records" array contains elements with
    default values - Stock_Record doesn't get populated.

    Any help would be greatly appreciated (I really mean it).

    Thank you.

  • ste

    #2
    Re: Inerop help

    Are you sure your c# Stock_Record matches the sizeof() for the c struct
    [color=blue]
    > typedef struct // num bytes
    > {
    > char MM;
    > char DD;
    > short YY;
    > float open;
    > float hi;
    > float lo;
    > float cl;
    > long vol;
    > char RS;
    > float oi;
    >
    > } *LPSTOCK_RECORD , Stock_Record;[/color]

    C' chars are 1 byte and i dont think they map onto C# strings.. which are
    probably sizeof( a pointer ) [ a guess ]
    Try changing your strings in your mapped record to 'byte' .. eg and make
    sure you map the C sizeof(long) to its .net counterpart

    The C' short is 2bytes and you should probably use int16 on 32bit machine.




    "yuriy_zuba rev" <yuriy_zubarev@ yahoo.ca> wrote in message
    news:1139601329 .140831.258290@ o13g2000cwo.goo glegroups.com.. .[color=blue]
    > Greetings,
    >
    > I apologize for re-posting this, but I'm running out of options on my
    > side.
    >
    > I've got a DLL that's not COM compatible and I'm stuck using interop
    > for the first time. I got couple of simple DLL calls all right but
    > cannot get the most important one to work.
    >
    > Here is documentation:
    >
    > ---
    >
    > int LoadSymbol( char*sym, void *data , int max_rec , bool
    > IGNORE_HOLIDAYS = true , bool RAWDATA = true ,usr_master_def *MasterRec
    > = 0);
    >
    > Returns: Number of days loaded. Negative number indicates an error.
    >
    > Parameters:
    >
    > sym - Points to the stock symbol to load.
    >
    > data - Points to an array of type Stock_Record.
    >
    > max_rec - An integer value...
    >
    > IGNORE_HOLIDAYS - Boolean value...
    >
    > RAWDATA - Boolean value...
    >
    > ---
    >
    > Here is C++ example:
    >
    > ...
    > char symbol[12];
    > #define MAX_RECS 10000;
    > Stock_Record data[MAX_RECS];
    > ...
    > num = LoadSymbol( symbol , &data[0] , MAX_RECS , FALSE , TRUE , 0 );
    > ...
    >
    > Here is a definition for Stock_Record struct:
    >
    > typedef struct
    > {
    > char MM;
    > char DD;
    > short YY;
    > float open;
    > float hi;
    > float lo;
    > float cl;
    > long vol;
    > char RS;
    > float oi;
    >
    > } *LPSTOCK_RECORD , Stock_Record;
    >
    > I don't know if a definition for Master_Rec is necessary (the last
    > argument for LoadSymbol function) since they just passed 0 in the
    > example. Pardon my naivety if it's totally wrong assumption.
    >
    > Anyway, when I call this function (LoadSymbol) I got a positive number
    > returned meaning that records have been read. The only problem - they
    > have no data.
    >
    > Here is C#:
    >
    > [DllImport("read er.dll")]
    > public static extern int LoadSymbol(stri ng symbol, Stock_Record[]
    > records, int maxDays, bool ignoreHolidays, bool rawData, int
    > masterRecord);
    >
    > (I might have screwed up with "int masterRecord" part...). The
    > following is C# brother of Stock_Record:
    >
    > [StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Ansi)]
    > public struct Stock_Record
    > {
    > public string MM;
    > public string DD;
    > public short YY;
    > public float open;
    > public float hi;
    > public float lo;
    > public float cl;
    > public long vol;
    > public string RS;
    > public float OI;
    >
    > }
    >
    > And some execution code:
    >
    > ...
    > Stock_Record[] records = new Stock_Record[100];
    > int daysLoaded = LoadSymbol("MSF T", records, 100, false, true, 0);
    > ...
    >
    > The situation here is that "records" array contains elements with
    > default values - Stock_Record doesn't get populated.
    >
    > Any help would be greatly appreciated (I really mean it).
    >
    > Thank you.
    >
    >
    >
    > ---
    > avast! Antivirus: Inbound message clean.
    > Virus Database (VPS): 0606-4, 10/02/2006
    > Tested on: 10/02/2006 22:32:38
    > avast! - copyright (c) 1988-2005 ALWIL Software.
    > http://www.avast.com
    >
    >
    >[/color]




    ---
    avast! Antivirus: Outbound message clean.
    Virus Database (VPS): 0606-4, 10/02/2006
    Tested on: 10/02/2006 22:42:27
    avast! - copyright (c) 1988-2005 ALWIL Software.
    Join hundreds of millions of others & get free antivirus for PC, Mac, & Android. Surf safely with our VPN. Download Avast!




    Comment

    Working...