1

I have a 64 bit DLL which I want to use in VBA. The example from VB.net won't work in VBA as Int32 is not a known VBA data type. Is it possible to get this working in VBA? If so, do I have to write my own class? I'm including a few lines of the example. Thank you.

Imports System
Imports System.Runtime.InteropServices

Friend Class LinkVCMOWRAP
    Declare Function wcmo_init Lib "vcmowr64.dll" ( _
        <MarshalAs(UnmanagedType.AnsiBStr), [In]()> ByRef WCMOarg_Handle As String, _
        <MarshalAs(UnmanagedType.AnsiBStr), [In]()> ByRef WCMOarg_User As String, _
        <Out()> ByRef IntPtr_DataOut As IntPtr, _
        <Out()> ByRef IntPtr_ErrOut As IntPtr) _
            As Int32 
Brendan
  • 43
  • 6
  • I guess the issue is two fold. `Int32` would translate to `Long` and not `Integer`, and `IntPtr` would be a 64-bit integer, that VBA cannot handle (I think). – John Alexiou Dec 12 '11 at 14:53
  • I have a 32bit example written in VBA is "As Long". The API documentation states `This works as it should in 32-bit applications (linked to vcmowrap.dll instead of vcmowr64.dll, of course.) Unfortunately, all versions of the Microsoft 64-bit .NET Framework prior to 4.0 contain a bug in the code that frees the unmanaged ANSI BSTRs returned from VCMOWRAP: it miscomputes the size of the prefixed length information in the BSTR, and so attempts to free memory at an incorrect address. This can result in memory leaks or even corrupted memory resulting in application crashes...` Thanks – Brendan Dec 12 '11 at 14:59
  • 64bit Office 2k10 VBA has longptr/longlong to handle 64bit apis – Alex K. Dec 12 '11 at 15:00
  • @Brendan - *zoom* (the sound your comment about `BSTRs` made going over my head). – John Alexiou Dec 12 '11 at 18:24

1 Answers1

0

Int32 and IntPtr aren't valid VBA data types. You'll need to rewrite the function converting the Int32 type to Long and the IntPtr type to Integer.

Andy Wilson
  • 1,383
  • 9
  • 15