Hi,
I'm writing a dll in C++ to get the serial hd, this is the code of the function:
The dll function calls it from an application written in C#:
function GetSerialHD() always returns null, but the same code in a console application C++ for testing works well.
thanks
I'm writing a dll in C++ to get the serial hd, this is the code of the function:
Code:
__declspec(dllexport) char* __stdcall char* GetSerialHD()
{
WmiQueryResult res = getWmiQueryResult(L"SELECT SerialNumber FROM Win32_PhysicalMedia", L"SerialNumber");
char* ret = NULL;
std::string strValue;
char* strReturn = NULL;
for (const auto& item : res.ResultList) {
strValue.assign(item.begin(), item.end());
ULONG ulSize = strlen(MyString) + sizeof(char);
strReturn = (char*)::CoTaskMemAlloc(ulSize);
strcpy(strReturn, strValue.c_str());
break;
}
return strReturn;
}Code:
[DllImport("mydll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPStr)]
public static extern string GetSerialHD();
...
string GetHD = GetSerialHD();thanks