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. Passing a string from a C++ DLL to VB

Passing a string from a C++ DLL to VB

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestiondiscussion
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.
  • J Offline
    J Offline
    JSadleir
    wrote on last edited by
    #1

    Hi All I'm trying to return a string from a dll to VBA as a BSTR but the variable always returns a null. What am I doing wrong? Are the variables passing out of scope before the result is returned? #include #include #include BSTR __stdcall SomeFunction(LPSTR cSPC) CHAR cTheString [255]; BSTR bResult; UINT iStringsLength=0; strcmp(cSPC,"Absolute Return"); iStringsLength = strlen(cTheString); bResult = SysAllocStringByteLen(cTheString,iStringsLength); return bResult; } The project builds, links and compiles successfully. Any thoughts about the problem would be gratefully accepted. Regards Jeremy

    C J 2 Replies Last reply
    0
    • J JSadleir

      Hi All I'm trying to return a string from a dll to VBA as a BSTR but the variable always returns a null. What am I doing wrong? Are the variables passing out of scope before the result is returned? #include #include #include BSTR __stdcall SomeFunction(LPSTR cSPC) CHAR cTheString [255]; BSTR bResult; UINT iStringsLength=0; strcmp(cSPC,"Absolute Return"); iStringsLength = strlen(cTheString); bResult = SysAllocStringByteLen(cTheString,iStringsLength); return bResult; } The project builds, links and compiles successfully. Any thoughts about the problem would be gratefully accepted. Regards Jeremy

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Your code post has got mangled up, but I have two comments. I don't see anywhere in your code that an assignment of a string of characters takes place to the variable, cTheString. Thats probably why no string shows up in your BSTR. I don't know a lot about BSTR types, but since you are making a call to SysAlloc.. to create the BSTR, I would seem to me that there must be a call to SysDealloc.. somewhere or the BSTR is going to leak. Just my musings. Try using the <pre> and </pre> tags to show your code better. Chris Meech I am Canadian. [heard in a local bar] Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]

      1 Reply Last reply
      0
      • J JSadleir

        Hi All I'm trying to return a string from a dll to VBA as a BSTR but the variable always returns a null. What am I doing wrong? Are the variables passing out of scope before the result is returned? #include #include #include BSTR __stdcall SomeFunction(LPSTR cSPC) CHAR cTheString [255]; BSTR bResult; UINT iStringsLength=0; strcmp(cSPC,"Absolute Return"); iStringsLength = strlen(cTheString); bResult = SysAllocStringByteLen(cTheString,iStringsLength); return bResult; } The project builds, links and compiles successfully. Any thoughts about the problem would be gratefully accepted. Regards Jeremy

        J Offline
        J Offline
        JSadleir
        wrote on last edited by
        #3

        Sorry Chris - I copied out part of the code incorrectly here is what it should have been - Thanks Jeremy BSTR __stdcall SomeFunction(LPSTR cSPC) CHAR cTheString [255]; BSTR bResult; UINT iStringsLength=0; strcpy(cTheString,"Absolute Return"); iStringsLength = strlen(cTheString); bResult = SysAllocStringByteLen(cTheString,iStringsLength); return bResult; }

        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