| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Comparison Data Type VB vs VC++
C++ library:
__declspec(dllexport) int WINAPI Caller(const char* username) Vb code: Private Declare Function Caller Lib "MyCaller.dll" () As Integer dim i as integer what! data type to by pass to caller function with correct using in c++ 'i = Caller ("user1") how to print log [const char* username] in c++, please suggest to me. |
|
#2
|
|||
|
|||
|
Re: Comparison Data Type VB vs VC++
Just and educated guess (been years since I've even seen VB code):
Code:
Private Declare Function Caller Lib "MyCaller.dll" (ByRef String) As Integer |
|
#3
|
|||
|
|||
|
Re: Comparison Data Type VB vs VC++
C++ library:
__declspec(dllexport) int WINAPI Caller(const wchar_t* username) Vb code: Private Declare Function Caller Lib "MyCaller.dll" () As Integer in c++ library use const wchar_t* then in vb code what use Thank you. |
|
#4
|
|||
|
|||
|
Re: Comparison Data Type VB vs VC++
I had a little free time on my lunch break so I decided to look into this.
As I mentioned upthread, I'm not at all familiar with VB and haven't even looked at any VB code in nearly 10 years, so a real VB programmer is likely to be able to come up with a more elegant solution. First, the C++ dll needs the extern "C" declaration to prevent name mangling, so if you don't have the source for your DLL in question, you're probably screwed anyway. The only way I could get this to work was to declare the VB dll export as taking a short array as it's parameter. Then I had to find a way to actually send a VB string as a short array which resulted in the function ToCString shown below (this was done in VS2008 so YMMV): Code:
Public Class Form1
Private Declare Function Caller Lib "..\..\..\..\Debug\VBwDLL.dll" (ByVal s As Short()) As Integer
Private Function ToCString(ByVal s As String) As Short()
Dim i As Integer
Dim x As Integer
Dim sarr() As Short
i = s.Length()
ReDim sarr(i)
For x = 0 To i - 1
sarr(x) = AscW(s.Substring(x, 1))
Next
sarr(x) = 0
Return sarr
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Long
i = Caller(ToCString("Hello World"))
TextBox1.Text = i.ToString()
End Sub
End Class
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|