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. C / C++ / MFC
  4. ATL (BSTR) to VB

ATL (BSTR) to VB

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadminhelpquestion
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.
  • D Offline
    D Offline
    Dan Madden
    wrote on last edited by
    #1

    I have a DLL that when I use it in VBS it works fine everytime...but when I use VB, it works the first time, but the second call returns TRASH. Can anyone explain why?? Here is a code snippet: STDMETHODIMP CSetShare::get_pNetDiskEnum(BSTR sServer, BSTR *pVal) { // NetserverDiskEnum Function to // Enumerate list of remote Server Drive Letters. const int ENTRY_SIZE = 3; // Drive letter, colon, NULL LPTSTR pBuf = NULL; DWORD dwLevel = 0; // level must be zero DWORD dwPrefMaxLen = -1; DWORD dwEntriesRead = 0; DWORD dwTotalEntries = 0; NET_API_STATUS nStatus; CComBSTR cstr1; // // Call the NetServerDiskEnum function. // nStatus = NetServerDiskEnum((LPSTR)sServer, dwLevel, (LPBYTE *) &pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, NULL); // // If the call succeeds, // if (nStatus == NERR_Success) { LPTSTR pTmpBuf; if ((pTmpBuf = pBuf) != NULL) { DWORD i; DWORD dwTotalCount = 0; // // Loop through the entries. // for (i = 0; i < dwEntriesRead; i++) { assert(pTmpBuf != NULL); if (pTmpBuf == NULL) { // On a remote computer, only members of the // Administrators or the Account Operators // local group can execute NetServerDiskEnum. // break; } // // Print drive letter for each drive; // the number of entries actually enumerated; and // the total number of entries available. // cstr1 += pTmpBuf; pTmpBuf += ENTRY_SIZE; dwTotalCount++; } cstr1 += pTmpBuf; } } else cstr1 = "System Error: No Such Machine"; if (pBuf != NULL) // Free the allocated buffer. NetApiBufferFree(pBuf); *pVal = (BSTR)cstr1; // Conversion to BSTR Type for VB return S_OK; } Thanks in advance, Dan

    M 1 Reply Last reply
    0
    • D Dan Madden

      I have a DLL that when I use it in VBS it works fine everytime...but when I use VB, it works the first time, but the second call returns TRASH. Can anyone explain why?? Here is a code snippet: STDMETHODIMP CSetShare::get_pNetDiskEnum(BSTR sServer, BSTR *pVal) { // NetserverDiskEnum Function to // Enumerate list of remote Server Drive Letters. const int ENTRY_SIZE = 3; // Drive letter, colon, NULL LPTSTR pBuf = NULL; DWORD dwLevel = 0; // level must be zero DWORD dwPrefMaxLen = -1; DWORD dwEntriesRead = 0; DWORD dwTotalEntries = 0; NET_API_STATUS nStatus; CComBSTR cstr1; // // Call the NetServerDiskEnum function. // nStatus = NetServerDiskEnum((LPSTR)sServer, dwLevel, (LPBYTE *) &pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, NULL); // // If the call succeeds, // if (nStatus == NERR_Success) { LPTSTR pTmpBuf; if ((pTmpBuf = pBuf) != NULL) { DWORD i; DWORD dwTotalCount = 0; // // Loop through the entries. // for (i = 0; i < dwEntriesRead; i++) { assert(pTmpBuf != NULL); if (pTmpBuf == NULL) { // On a remote computer, only members of the // Administrators or the Account Operators // local group can execute NetServerDiskEnum. // break; } // // Print drive letter for each drive; // the number of entries actually enumerated; and // the total number of entries available. // cstr1 += pTmpBuf; pTmpBuf += ENTRY_SIZE; dwTotalCount++; } cstr1 += pTmpBuf; } } else cstr1 = "System Error: No Such Machine"; if (pBuf != NULL) // Free the allocated buffer. NetApiBufferFree(pBuf); *pVal = (BSTR)cstr1; // Conversion to BSTR Type for VB return S_OK; } Thanks in advance, Dan

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      *pVal = (BSTR)cstr1; There's your problem right there. cstr1 is a local variable. Change it to

      *pVal = cstr1.Detach();

      --Mike-- http://home.inreach.com/mdunn/ Push the button, Frank.

      D 1 Reply Last reply
      0
      • M Michael Dunn

        *pVal = (BSTR)cstr1; There's your problem right there. cstr1 is a local variable. Change it to

        *pVal = cstr1.Detach();

        --Mike-- http://home.inreach.com/mdunn/ Push the button, Frank.

        D Offline
        D Offline
        Dan Madden
        wrote on last edited by
        #3

        Thanks Michal, it is bed time in this part of the world...I will test this first thing in the morning, and thanks for the quick response! Thanks in advance, Dan

        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