Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Problem in getting data from server

Problem in getting data from server

Scheduled Pinned Locked Moved ATL / WTL / STL
c++helpsysadminannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MANISH RASTOGI
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • M 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

      E Offline
      E Offline
      Ernest Laurentin
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • E 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

        M Offline
        M Offline
        MANISH RASTOGI
        wrote on last edited by
        #3

        Thanks Ernest Laurentin BSTR is working.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups