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. String from VB to VC

String from VB to VC

Scheduled Pinned Locked Moved ATL / WTL / STL
helpc++graphicstutorial
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.
  • S Offline
    S Offline
    SiddharthAtw
    wrote on last edited by
    #1

    Please help me I lost my night sleep. Tell in simple code. From my VB client I am passing simple string "Siddharth", to a win32 dll function GetUserName(DATATYPE)(if DAtatype is BSTR or wstring tell me how to convert it into string in dll function declaration). My program should run in 98 as well as NT. I am trying lot of examples but they all are for long. When I convert it to string nothing works out. VB client Dim x as string x = "String" GetStringFromVb(wstring *) end Win32 GetStringFromVb(wstring*) { vector MyString; MyString.push_back(wstring); { //..Lot of string manipulation } } One more issue. in the win32 DLL.h if I declare stl parameter, it is not accepted by the compiler.

    A 1 Reply Last reply
    0
    • S SiddharthAtw

      Please help me I lost my night sleep. Tell in simple code. From my VB client I am passing simple string "Siddharth", to a win32 dll function GetUserName(DATATYPE)(if DAtatype is BSTR or wstring tell me how to convert it into string in dll function declaration). My program should run in 98 as well as NT. I am trying lot of examples but they all are for long. When I convert it to string nothing works out. VB client Dim x as string x = "String" GetStringFromVb(wstring *) end Win32 GetStringFromVb(wstring*) { vector MyString; MyString.push_back(wstring); { //..Lot of string manipulation } } One more issue. in the win32 DLL.h if I declare stl parameter, it is not accepted by the compiler.

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      hi sidharth, when u r passing string in vc++ they are accepted in BSTR format. so u have to first change into CString and then to char* to use it as a string. function used to perform this is #include CString CString_str = _T(""); if (BSTR_str != NULL) // To be sure that input string is valid... { CString s; LPSTR p = s.GetBuffer(::SysStringLen(BSTR_str) + 1); BOOL UsedDefaultChar; ::WideCharToMultiByte(CP_ACP, 0, BSTR_str, -1, p, ::SysStringLen(BSTR_str)+1, NULL, &UsedDefaultChar); if (UsedDefaultChar) // BSTR_str contains an ANSI string CString_str = (LPCTSTR)BSTR_str; else // BSTR_str contains an UNICODE string CString_str = (LPCWSTR)BSTR_str; } char *temp = LPSTR(CString_str); further if u have to include MFC support at the time of creating new ATL project I hope it will help u. Ritu

      S 1 Reply Last reply
      0
      • A Anonymous

        hi sidharth, when u r passing string in vc++ they are accepted in BSTR format. so u have to first change into CString and then to char* to use it as a string. function used to perform this is #include CString CString_str = _T(""); if (BSTR_str != NULL) // To be sure that input string is valid... { CString s; LPSTR p = s.GetBuffer(::SysStringLen(BSTR_str) + 1); BOOL UsedDefaultChar; ::WideCharToMultiByte(CP_ACP, 0, BSTR_str, -1, p, ::SysStringLen(BSTR_str)+1, NULL, &UsedDefaultChar); if (UsedDefaultChar) // BSTR_str contains an ANSI string CString_str = (LPCTSTR)BSTR_str; else // BSTR_str contains an UNICODE string CString_str = (LPCWSTR)BSTR_str; } char *temp = LPSTR(CString_str); further if u have to include MFC support at the time of creating new ATL project I hope it will help u. Ritu

        S Offline
        S Offline
        SiddharthAtw
        wrote on last edited by
        #3

        Thanx a lot buddy. That was a breather. I will try and get back.But I am not using MFC. and if I include it will create conflict. Any way let me try first.

        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