Hello Ladies and Gentlemen of Code Project,
I am trying to figure out how to send and receive strings from a function written in C++ (using Visual Studio 2015) to VB6.
Please be aware that the strings will be sent and received from the argument list of the function
I am experienced with VB6, but not C++!
The declaration is as follows:
VBDLLFUNC(int) MDNSa35dbd7v2(int service, int AC0_CryptoKeyTable, unsigned char* seed, unsigned char* key);
The code/wrapper is as follows:
VBDLLFUNC(int) MDNSa35dbd7v2(int service, int AC0_CryptoKeyTable, unsigned char* seed, unsigned char* key) {
return (a35dbd7v2(service, AC0_CryptoKeyTable, seed, key));
}
Where #define VBDLLFUNC(TypeName) DLLEXPORT TypeName __stdcall
I have the following declaration in my VB6 code:
Declare Function MDNSa35dbd7v2 Lib "MDTestDLL.dll" (ByVal service As Long, ByVal
CryptoKeyTable As Long, ByVal Seed As String, ByRef Key As String) As Long
In my Form Load event I call the function as follows:
Private Sub Form_Load()
Dim lRetVal As Long
Dim sKey As String
Dim sSeed As String
The customer is telling me that if call MDNSa35dbd7v2 with a sSeed = 5 bytes of 11 (I don't know if they mean 11 dec or B hex) as the sSeed
sSeed = Chr(11) & Chr(11) & Chr(11) & Chr(11) & Chr(11)
I should get back 5 bytes of 22 for sKey
lRetVal = MDNSa35dbd7v2(&H1, &H3C, sSeed, sKey)
End Sub
The question that I have is this, since I am dealing with VB6 then the functions declaration and the function itself should maybe be declared as follows:
VBDLLFUNC(int) MDNSa35dbd7v2(int service, int AC0_CryptoKeyTable, BSTR seed, BSTR
key);
VBDLLFUNC(int) MDNSa35dbd7v2(int service, int AC0_CryptoKeyTable, BSTR seed, BSTR key) {
return (a35dbd7v2(service, AC0_CryptoKeyTable, seed, key));
}
Please also be aware that the header declaration for a35dbd7v2 is as follows:
extern __declspec(dllexport) int a35dbd7v2(int service, int AC0_CryptoKeyTable, unsigned char* seed, unsigned char* key);
Since I am calling this funvtion from VB6 and VB6 uses BSTR when dealing with strings, then how would I convert BSTR to unsigned char*?
Please advise
Thank you
What I have tried:
I have been googling and think that I might be close