Re: Passing a string as reference from a VB 3.0 application to a VC++ 3.0 DLL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Arnau Font (afont_at_nospam-ipssoft.com)
Date: 04/23/04


Date: Fri, 23 Apr 2004 12:02:25 +0200

Well, the problem was in the declare function in the VB code, the String
must be passed as ByVal.

Public Declare Function GetMachineIdentification Lib "ProtocolsDLL" (ByVal
ident As String, ByRef size As Long) As Integer

"Arnau Font" <afont@nospam-ipssoft.com> escribió en el mensaje
news:OikBjgEKEHA.2380@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I'm trying to make a DLL that contains a procedure that receives a string
as
> parameter, fills it and returns to the application that has made the call.
> The DLL is made under VC++ 3.0 and the calling application in VB 3.0.
>
> The code of the DLL is this:
>
> PROTOCOLSDLL_API void GetMachineIdentification(LPWSTR ident) {
> for (unsigned long i=0;i<128;i++) {
> ident[i]=_T('a'); //This should be more complicated, but I simplified
it
> for testing
> }
> }
>
> And the code for the calling is:
>
> ident = String(128, " ")
> Call GetMachineIdentification(ident)
> Text1.Text = Text1.Text & Mid(ident, 1, 3) & vbNewLine
>
> But it doesn't print anything in the memo (Text1)!
> Does anyone have any idea??
>
> Thanks,
> Arnau.
>
>



Relevant Pages

  • Re: String function return
    ... ByVal s2 As String) As Long ... Declare Function fnReturnString Lib "VBDLLTest.dll" (ByVal x As ... // Pass strings from VB to the DLL ...
    (microsoft.public.vc.language)
  • Re: Upgrading Ingres Client from 2.5 to 2.6
    ... 'Public Declare Function RegCloseKey Lib "advapi32.dll" Alias ... "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ... ' DoEvents ...
    (comp.databases.ingres)
  • Re: Issue designing a class module that uses OleLoadPicture
    ... code in with an extra line to convert to string (StrConv(variable, ... Declare Function SetStretchBltMode Lib "gdi32" (_ ... 'nWidth = The width of the destination image ... Public Const INVALID_SOCKET = -1 ...
    (comp.databases.ms-access)
  • Re: Explicit Linking of DLLs in VB.net
    ... yes this technique will only work on managed assemblys (exe or dll) ... "YourObject" is a form and is limited to the form methods. ... Wel implement propertys, methods, events in your interface and start ... Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Explicit Linking of DLLs in VB.net (attn Michel or any others)
    ... loads the dll and finds a form in the dll. ... Dim extForm As Form = extAssembly.CreateInstance("test.entry", ... Wel implement propertys, methods, events in your interface and start ... Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, ...
    (microsoft.public.dotnet.languages.vb)