I have had major troubles with this one. First of all I needed to work out how to convert char[] to string
Now my string returns the following error when used in VB
PInvokeStackImbalance was detected
Message: A call to PInvoke function 'IVcom!IVcom.Nortronics.Indigo.IVcomObjects::GetMAC' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
The C++ code
Now my string returns the following error when used in VB
PInvokeStackImbalance was detected
Message: A call to PInvoke function 'IVcom!IVcom.Nortronics.Indigo.IVcomObjects::GetMAC' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
VB.NET:
Public Declare Function GetMAC Lib "IVserial.dll" (ByVal IPddress As String) As String
Public Function returnMAC(ByVal mIPaddress As String) As String
Dim strMAC As String
strMAC = GetMAC(mIPaddress)
returnMAC = strMAC
End Function
The C++ code
VB.NET:
string __stdcall GetMAC(const char *IPAddress)
{
VBDEVICEINFO deviceInfo;
char *pszIpAddr = NULL;
BOOL fSuccess;
const VBDEVICEINFO *pDeviceInfo;
fSuccess = VbQueryDevice( IPAddress, &deviceInfo );
pDeviceInfo = &deviceInfo;
// VBMSRV_PLAYBACKINFO pbInfo;
char Buffer[17];
sprintf(Buffer,
"%02X:%02X:%02X:%02X:%02X:%02X",
pDeviceInfo->macAddress.abMacAddr[ 0 ],
pDeviceInfo->macAddress.abMacAddr[ 1 ],
pDeviceInfo->macAddress.abMacAddr[ 2 ],
pDeviceInfo->macAddress.abMacAddr[ 3 ],
pDeviceInfo->macAddress.abMacAddr[ 4 ],
pDeviceInfo->macAddress.abMacAddr[ 5 ]
);
return std::string(Buffer);
}