Problem in getting data from server
-
Hi Friends, I am using VC++ 6.0 I careated an exe server using ATL. It has one interface mdethod "ComputerName". Prototype of method is : [id(1), helpstring("ComputerName")] HRESULT ComputerName([out] short *pnSize, [out, size_is(1, *pnSize)] unsigned char **ppszComputerName); Server implementation of this function is : STDMETHODIMP CTestServer::ComputerName(short *pnSize, unsigned char **ppszComputerName) { TCHAR szBuffer[100] = {0}; DWORD dwSize = 0; int iLength = 0; dwSize = sizeof(szBuffer); GetComputerName(szBuffer, &dwSize); iLength = ::lstrlen(szBuffer); *pnSize = iLength; *ppszComputerName = (unsigned char *) CoTaskMemAlloc(iLength + 1); ::lstrcpy((char *) *ppszComputerName, szBuffer); return(S_OK); } Client Side Implementation is : ITestServer *pITestServer = NULL; HRESULT hResult = NULL; short int nSize = 0; unsigned char *pszComputerName = NULL; CoInitialize(NULL); hResult = CoCreateInstance(....); if(SUCCEEDED(hResult)) { pITestServer->ComputerName(&nSize, &pszComputerName); // Here is problem only pszComputerName[0] contains valid data. other contains invalid data. nSize contains valid length. pITestServer->Release(); } CoUninitialize(); I am unable to get the reason. Anyone can help me please. Manish Rastogi
-
Hi Friends, I am using VC++ 6.0 I careated an exe server using ATL. It has one interface mdethod "ComputerName". Prototype of method is : [id(1), helpstring("ComputerName")] HRESULT ComputerName([out] short *pnSize, [out, size_is(1, *pnSize)] unsigned char **ppszComputerName); Server implementation of this function is : STDMETHODIMP CTestServer::ComputerName(short *pnSize, unsigned char **ppszComputerName) { TCHAR szBuffer[100] = {0}; DWORD dwSize = 0; int iLength = 0; dwSize = sizeof(szBuffer); GetComputerName(szBuffer, &dwSize); iLength = ::lstrlen(szBuffer); *pnSize = iLength; *ppszComputerName = (unsigned char *) CoTaskMemAlloc(iLength + 1); ::lstrcpy((char *) *ppszComputerName, szBuffer); return(S_OK); } Client Side Implementation is : ITestServer *pITestServer = NULL; HRESULT hResult = NULL; short int nSize = 0; unsigned char *pszComputerName = NULL; CoInitialize(NULL); hResult = CoCreateInstance(....); if(SUCCEEDED(hResult)) { pITestServer->ComputerName(&nSize, &pszComputerName); // Here is problem only pszComputerName[0] contains valid data. other contains invalid data. nSize contains valid length. pITestServer->Release(); } CoUninitialize(); I am unable to get the reason. Anyone can help me please. Manish Rastogi
Hi Manish, If you want to pass string, use BSTR. COM marshalling works a bit different. If you plan to transfer 'byte*', use Safearray of byte.
God bless, Ernest Laurentin
-
Hi Manish, If you want to pass string, use BSTR. COM marshalling works a bit different. If you plan to transfer 'byte*', use Safearray of byte.
God bless, Ernest Laurentin
Thanks Ernest Laurentin BSTR is working.