dll problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: dll problem

  1. #1
    James Guest

    dll problem


    Hello all,

    I'm hoping that some of you guys will have an anwer to my problem.
    A few months ago I wrote a VB6 program that uses a VC++6 dll to create, parse,
    etc. messages from a serial communication line. The serial communication
    part isn't important here. It's the dll functions that are giving me a problem.
    The particular one I'm trouble with is one I call "MakeMessage". Here's the
    function def in the dll:

    int MakeMessage(char *dst, int command, int x, int y, int msgID, char *src)

    I declare it like this in VB.net:

    declare auto function MakeMessage Lib "Utils.dll" (byval sMessage as
    string, byval command as integer, byval panel as integer, byval msgid

    as long, byval strdata as string) as long

    I'm trying to rewrite this VB6 program in VB.Net. When I use this function
    in VB6 it works fine. What it does is uses the last four parameters and makes
    them into a formatted message and places it into the first parameter, dst.
    When the function completes there should be a text message in the variable
    passed to the function and the length of the text message is returned.
    When I use this function in VB.Net I don't get any text values in the string
    passed into dst, but I get a bunch of unreadable characters and the length
    returned is something like 9151031864033542164.
    Here's an example of using this function.

    dim strData as string = ""
    dim Command as long = 41
    dim Num as long = 6
    dim msgcntr as long = 0
    dim data as string = "0000"
    dim length as long = 0

    length = MakeMessage(strData, Command, Num, msgcntr, data)

    This will return:

    length = 9151031864033542164
    strData = Nothing

    I should return:

    length = 25
    strData = ":19,A0,06,379D,0000,0000;"

    I don't know what it could be. Like I said, it works perfectly in VB6 but
    I want to use it in VB.net and this is what happens. Could it be because
    Integers are larger in .Net than in VB6? Or could it be because of the way
    it is declared in VB.net?

    The only difference I can find in the usage is that in VB6 I clear out the
    destination string (dst) variable, strData, using the string() function:

    strData = String(65, &h0)

    This initializes strData to 65 characters where each character code is 0x00.
    But this is not an option in vb.net. Does anyone know how to do the same
    thing in .net?

    If anyone has taken the time to read this, thank you very much. I really
    look forward to reading your responses and getting some clue as to why it
    doesn't want to work the same way.

    Thanks again,
    James

  2. #2
    Bill McCarthy Guest

    Re: dll problem

    Hi James,

    How are you determining the length of the returned string ?

    Also, try setting sMessage parameter to ByRef instead of ByVal, although that
    would normally require the definition ot be char **dst. So what you probably need
    to do is pre-populate the string wiht enough characters to hold the returned data,
    just as you did in VB6.


    "James" <wolfjj79@sbcglobal.net> wrote in message news:3cadc4e2$1@10.1.10.29...
    >
    > Hello all,
    >
    > I'm hoping that some of you guys will have an anwer to my problem.
    > A few months ago I wrote a VB6 program that uses a VC++6 dll to create, parse,
    > etc. messages from a serial communication line. The serial communication
    > part isn't important here. It's the dll functions that are giving me a problem.
    > The particular one I'm trouble with is one I call "MakeMessage". Here's the
    > function def in the dll:
    >
    > int MakeMessage(char *dst, int command, int x, int y, int msgID, char *src)
    >
    > I declare it like this in VB.net:
    >
    > declare auto function MakeMessage Lib "Utils.dll" (byval sMessage as
    > string, byval command as integer, byval panel as integer, byval msgid
    >
    > as long, byval strdata as string) as long
    >
    > I'm trying to rewrite this VB6 program in VB.Net. When I use this function
    > in VB6 it works fine. What it does is uses the last four parameters and makes
    > them into a formatted message and places it into the first parameter, dst.
    > When the function completes there should be a text message in the variable
    > passed to the function and the length of the text message is returned.
    > When I use this function in VB.Net I don't get any text values in the string
    > passed into dst, but I get a bunch of unreadable characters and the length
    > returned is something like 9151031864033542164.
    > Here's an example of using this function.
    >
    > dim strData as string = ""
    > dim Command as long = 41
    > dim Num as long = 6
    > dim msgcntr as long = 0
    > dim data as string = "0000"
    > dim length as long = 0
    >
    > length = MakeMessage(strData, Command, Num, msgcntr, data)
    >
    > This will return:
    >
    > length = 9151031864033542164
    > strData = Nothing
    >
    > I should return:
    >
    > length = 25
    > strData = ":19,A0,06,379D,0000,0000;"
    >
    > I don't know what it could be. Like I said, it works perfectly in VB6 but
    > I want to use it in VB.net and this is what happens. Could it be because
    > Integers are larger in .Net than in VB6? Or could it be because of the way
    > it is declared in VB.net?
    >
    > The only difference I can find in the usage is that in VB6 I clear out the
    > destination string (dst) variable, strData, using the string() function:
    >
    > strData = String(65, &h0)
    >
    > This initializes strData to 65 characters where each character code is 0x00.
    > But this is not an option in vb.net. Does anyone know how to do the same
    > thing in .net?
    >
    > If anyone has taken the time to read this, thank you very much. I really
    > look forward to reading your responses and getting some clue as to why it
    > doesn't want to work the same way.
    >
    > Thanks again,
    > James




  3. #3
    Ian R Guest

    Re: dll problem

    Isn't an int in VC++6 a short in VB.NET ?

    "Bill McCarthy" <bill_mcc@iprimus.com.au> wrote in message
    news:3caef1c4@10.1.10.29...
    > Hi James,
    >
    > How are you determining the length of the returned string ?
    >
    > Also, try setting sMessage parameter to ByRef instead of ByVal, although

    that
    > would normally require the definition ot be char **dst. So what you

    probably need
    > to do is pre-populate the string wiht enough characters to hold the

    returned data,
    > just as you did in VB6.
    >
    >
    > "James" <wolfjj79@sbcglobal.net> wrote in message

    news:3cadc4e2$1@10.1.10.29...
    > >
    > > Hello all,
    > >
    > > I'm hoping that some of you guys will have an anwer to my problem.
    > > A few months ago I wrote a VB6 program that uses a VC++6 dll to create,

    parse,
    > > etc. messages from a serial communication line. The serial communication
    > > part isn't important here. It's the dll functions that are giving me a

    problem.
    > > The particular one I'm trouble with is one I call "MakeMessage". Here's

    the
    > > function def in the dll:
    > >
    > > int MakeMessage(char *dst, int command, int x, int y, int msgID, char

    *src)
    > >
    > > I declare it like this in VB.net:
    > >
    > > declare auto function MakeMessage Lib "Utils.dll" (byval sMessage as
    > > string, byval command as integer, byval panel as integer, byval

    msgid
    > >
    > > as long, byval strdata as string) as long
    > >
    > > I'm trying to rewrite this VB6 program in VB.Net. When I use this

    function
    > > in VB6 it works fine. What it does is uses the last four parameters and

    makes
    > > them into a formatted message and places it into the first parameter,

    dst.
    > > When the function completes there should be a text message in the

    variable
    > > passed to the function and the length of the text message is returned.
    > > When I use this function in VB.Net I don't get any text values in the

    string
    > > passed into dst, but I get a bunch of unreadable characters and the

    length
    > > returned is something like 9151031864033542164.
    > > Here's an example of using this function.
    > >
    > > dim strData as string = ""
    > > dim Command as long = 41
    > > dim Num as long = 6
    > > dim msgcntr as long = 0
    > > dim data as string = "0000"
    > > dim length as long = 0
    > >
    > > length = MakeMessage(strData, Command, Num, msgcntr, data)
    > >
    > > This will return:
    > >
    > > length = 9151031864033542164
    > > strData = Nothing
    > >
    > > I should return:
    > >
    > > length = 25
    > > strData = ":19,A0,06,379D,0000,0000;"
    > >
    > > I don't know what it could be. Like I said, it works perfectly in VB6

    but
    > > I want to use it in VB.net and this is what happens. Could it be because
    > > Integers are larger in .Net than in VB6? Or could it be because of the

    way
    > > it is declared in VB.net?
    > >
    > > The only difference I can find in the usage is that in VB6 I clear out

    the
    > > destination string (dst) variable, strData, using the string() function:
    > >
    > > strData = String(65, &h0)
    > >
    > > This initializes strData to 65 characters where each character code is

    0x00.
    > > But this is not an option in vb.net. Does anyone know how to do the same
    > > thing in .net?
    > >
    > > If anyone has taken the time to read this, thank you very much. I really
    > > look forward to reading your responses and getting some clue as to why

    it
    > > doesn't want to work the same way.
    > >
    > > Thanks again,
    > > James

    >
    >




  4. #4
    Cali LaFollett Guest

    Re: dll problem

    > Isn't an int in VC++6 a short in VB.NET ?

    No, "int" is a 32 bit Signed Integer.

    Cal




  5. #5
    Ian R Guest

    Re: dll problem

    In VC++. Ok, thanks. Be nice if it was the same everywhere..

    "Cali LaFollett" <cali@please_no_spam_visionized.com> wrote in message
    news:3caf8933@10.1.10.29...
    > > Isn't an int in VC++6 a short in VB.NET ?

    >
    > No, "int" is a 32 bit Signed Integer.
    >
    > Cal
    >
    >
    >




  6. #6
    James Guest

    Re: dll problem


    Thanks for the suggestion, Cal. The only thing that might be a problem is
    that I wanted to pre-populate with nulls, not nullstring, but all bits turned
    off (0) for the entire string and still have something inside the string.
    If I try to do that is .net I get the variable as being NOTHING istead of
    say, 4 bytes where all bits = 0. If I pre-populate it with something other
    that 0 bits, like all bits turned on maybe (haven't tried yet), I have the
    problem that sometimes the value going into that variable is smaller than
    the variable length and I want to keep the trailing zeros.
    I don't know, maybe I'm just not seeing the correct way to do this in .net

    However, I have rigged a way to do it by creating a VB6 dll file that has
    all the VC++ dll function calls in it and createing public functions that
    have the same parameters as the dll functions I need and then calling the
    VB6 dll functions instead. In short I wrote a VB6 dll to access a VC++6 dll
    from VB.Net. I know it's not the best coding technique but it seems to work
    the way I need it to.

    Thanks again for the suggestion.
    James


    "Ian R" <ianr@na.net> wrote:
    >In VC++. Ok, thanks. Be nice if it was the same everywhere..
    >
    >"Cali LaFollett" <cali@please_no_spam_visionized.com> wrote in message
    >news:3caf8933@10.1.10.29...
    >> > Isn't an int in VC++6 a short in VB.NET ?

    >>
    >> No, "int" is a 32 bit Signed Integer.
    >>
    >> Cal
    >>
    >>
    >>

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center