CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Posts
    18

    Passing a string arg to a DLL function

    Hello,

    I've been trying to pass a string reference to a DLL function (created by myself). I always get the only 4 bytes in the return string 'DataOut':


    private Sub CommandRead_Click()

    Dim DataOut as string
    Dim BlkNo as Integer
    Dim BlkLen as Integer

    DataOut = 0

    'Read Data
    BlkNo = 0
    BlkLen = 32
    Status = ReadBlock(BlkNo, BlkLen, DataOut)
    Text1.Text = DataOut

    End Sub

    public Declare Function ReadBlock Lib "TestMemCard.dll" (byval BlkNo as Integer, byval BlkLen as Integer, byval DataOut as string) as Long




    During creation of "TestMemCard.dll" , the function 'ReadBlock' was defined as

    extern "C" long CALLDLL WINAPI ReadBlock(BYTE BlkNo,BYTE BlkLen,char *DataOut)

    ...where 'BYTE' is unsigned char.

    I tried both 'ByVal' and 'ByRef' for 'DataOut', and get always 4 bytes for 'ByVal' while 'RyRef' gives illegal operation.

    I appreciate if anyone could help. Thanks.



  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Passing a string arg to a DLL function

    You are passing an empty string - you should preinitialise it if you are going to write to it i.e.:


    Dim DataOut as string

    DataOut = string$(1024,0)





    Hope this helps,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured