I'm having trouble trying to load map names into a list using vb6. Here is the code:
------------------------------------------------------------------------------------
Private Declare Function Init Lib "UnitSync.dll" (ByVal isServer As Boolean, ByVal Id As Long) As Long
Private Declare Sub UnInit Lib "UnitSync.dll" ()
Private Declare Function InitArchiveScanner Lib "UnitSync.dll" () As Long
Private Declare Function GetMapCount Lib "UnitSync.dll" () As Long
Private Declare Function GetMapName Lib "UnitSync.dll" (ByVal Index As Long) As String
...
Private Sub ListMaps()
Dim NumMaps As Long
Dim Num As Long
If Init(True, 0) <> 1 Then Exit Sub
InitArchiveScanner
NumMaps = GetMapCount
For Num = 0 To NumMaps - 1 'get the the map names
List1.AddItem GetMapName(Num)
Next Num
UnInit
End Sub
------------------------------------------------------------------------------
GetMapCount() returns the correct number of maps but GetMapName() just returns an empty string. I've been trying to find what the problem is for hours without any luck.
If anyone can help me out it would be very very very....good, thanks.
Android_X
unitsync.dll help
Moderator: Moderators
If GetMapCount works then everything should have been set up ok internally in unitsync at least, as GetMapName just uses information created by the call to GetMapCount. Perhaps it could be some issue with the type conversion that VB has to do. The function returns a pointer to a nullterminated string, perhaps you can try declaring it as some sort of array instead. I don't really know VB though, so not sure what kind of types are available.
Thanks Fnordia. I think you might be right about the type conversion vb does, although it should work from what I can see.Perhaps it could be some issue with the type conversion that VB has to do.
Unforunatly vb does not have char arrays so that isn't an option but I'll mess around with the types a bit and see if I can get it working(maybe a byte array?).perhaps you can try declaring it as some sort of array instead.
Can you simply nto itnerpret them as characters btu rather what they actually are, integers? Read the array as an array of itnegers then covnert it into a string using the ascii codes, something akin to the c++ function itoa() or atoi()
taken from MSDN:
That might help you, ti's got vb code examples
However reading this it gives the difference between LPSTR format of the dll and the BSTR data type which VB uses, I'd post all the seperate links but they show up in msdn as the same page but they're in the side menu. There's a covnersion table in there of C++ types and their VB equivilants
Also I thought this might be of help:
http://www.cygwin.com/ml/cygwin/2003-06/msg00271.html
It's from somebody havign a similair problem in VS .Net
Also:
taken from MSDN:
http://msdn.microsoft.com/library/defau ... cedure.aspThis approach will also work for string arrays. A DLL procedure written in C treats a string array as an array of pointers to string data, which is the same way Visual Basic defines a string array.
That might help you, ti's got vb code examples
However reading this it gives the difference between LPSTR format of the dll and the BSTR data type which VB uses, I'd post all the seperate links but they show up in msdn as the same page but they're in the side menu. There's a covnersion table in there of C++ types and their VB equivilants
Also I thought this might be of help:
http://www.cygwin.com/ml/cygwin/2003-06/msg00271.html
It's from somebody havign a similair problem in VS .Net
Also:
Standard C coding usually uses char arrays (byte arrays) to hold its strings. These strings are typically held in a fixed size array and terminated with a null character ( Chr(0) ). When we work with strings between C and VB we have 2 options. We can either send the string as our native BSTRs or we can specify to have the VB runtime convert our BSTR to an standard null terminated C string for us as it makes the call. If we pass our String ByRef to the C function, it will be passed as a BSTR. If we pass it ByVal then the VB runtime will make a copy of our string, convert it to a null terminated byte array of characters, then pass that to the called function. If your C function receives the BSTR, you can use the Sys*String functions (examples provided) to read & modify it as you wish. If you are dealing with the byte array C style string, you can read and access it as you would a normal C String. If the byte array is big enough, you can actually modify its contents to be returned to VB. This is because on return the VB runtime copies the byte array back into the BSTR variable we passed into it. You cannot however exceed the bounds of the byte array you were passed or else you will be corrupting other things in memory and will most likly crash. When working with a native BSTR you are free to modify the size of the string through the Sys*String functions (ex. SysReAllocString) because the API will handles its own memory management.