Hello. I have a C++ DLL ("unmanaged" I think, though I'm not sure exactly what that means).
I need to call it from both VB.NET 2003, and VB6. I can do so from VB.NET (see below). However, I can't figure out how to call it from VB6.
Here's the definition of the function I need to call:
I've tried various declarations such as:Code:int SomeFunction(const char *fileName, unsigned int **packedTemplate, unsigned int **packedMask, int *width, int *height);
But I always get: Run-time error ‘49’: Bad DLL calling conventionCode:Private Declare Function SomeFunction Lib "XYZ.dll" ( _ ByVal FileName As String, _ ByRef PackedTemplatePtr As Variant, _ ByRef PackedMaskPtr As Variant, _ ByRef Width As Long, ByRef Height As Long _ ) As Integer
I can call this from VB.NET using this declaration:
This requires some memory management, which I do using Marshal:Code:<DllImport("XYZ.dll")> _ Private Function SomeFunction _ (ByVal FileName As String, _ ByRef PackedTemplatePtr As IntPtr, _ ByRef PackedMaskPtr As IntPtr, _ ByRef Width As Integer, ByRef Height As Integer) _ As Integer End Function
Any suggestions greatly appreciated, thanks!Code:Dim TemplatePtr As IntPtr '= Marshal.AllocHGlobal(TemplateSize) Dim MaskPtr As IntPtr '= Marshal.AllocHGlobal(TemplateSize) SomeFunction (BmpFile, TemplatePtr, MaskPtr, Width, Height) Marshal.Copy(TemplatePtr, PackedTemplate, 0, TemplateSize) Marshal.Copy(MaskPtr, PackedMask, 0, TemplateSize)




Reply With Quote