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. CString to CComBSTR to use for IDirectorySearch

CString to CComBSTR to use for IDirectorySearch

Scheduled Pinned Locked Moved C / C++ / MFC
databasequestion
4 Posts 3 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.
  • B Offline
    B Offline
    bjolletts
    wrote on last edited by
    #1

    Im writing a program that searches an ActiveDirectory database and want the program to take a search argument like "moderator" through a dialog window and the program will search for everyone that is a moderator. So my search function takes a CString as a parameter But to use it in the search it must be a LPWSTR (pszSearchFilter). HRESULT ExecuteSearch(LPWSTR pszSearchFilter, LPWSTR* pAttributeNames, DWORD dwNumberAttributes, PADS_SEARCH_HANDLE phSearchHandle); I havetried to builda CString that looks like this: L"(&(objectClass=user)(title=moderator))"; And then it must be converted to LPWSTR or CComBSTR or whatever that works ... any ideas how ? Thanks in advance !

    M J B 3 Replies Last reply
    0
    • B bjolletts

      Im writing a program that searches an ActiveDirectory database and want the program to take a search argument like "moderator" through a dialog window and the program will search for everyone that is a moderator. So my search function takes a CString as a parameter But to use it in the search it must be a LPWSTR (pszSearchFilter). HRESULT ExecuteSearch(LPWSTR pszSearchFilter, LPWSTR* pAttributeNames, DWORD dwNumberAttributes, PADS_SEARCH_HANDLE phSearchHandle); I havetried to builda CString that looks like this: L"(&(objectClass=user)(title=moderator))"; And then it must be converted to LPWSTR or CComBSTR or whatever that works ... any ideas how ? Thanks in advance !

      M Offline
      M Offline
      Mike Beckerleg
      wrote on last edited by
      #2

      Try converting the CString into a _bstr_t CString searchParameter("the search string"); _bstr_t bstr(searchParameter); Mike

      1 Reply Last reply
      0
      • B bjolletts

        Im writing a program that searches an ActiveDirectory database and want the program to take a search argument like "moderator" through a dialog window and the program will search for everyone that is a moderator. So my search function takes a CString as a parameter But to use it in the search it must be a LPWSTR (pszSearchFilter). HRESULT ExecuteSearch(LPWSTR pszSearchFilter, LPWSTR* pAttributeNames, DWORD dwNumberAttributes, PADS_SEARCH_HANDLE phSearchHandle); I havetried to builda CString that looks like this: L"(&(objectClass=user)(title=moderator))"; And then it must be converted to LPWSTR or CComBSTR or whatever that works ... any ideas how ? Thanks in advance !

        J Offline
        J Offline
        Jonathan Craig
        wrote on last edited by
        #3

        You should be able to do it like this...

        CString str("Hack on!");
        BSTR bstr = str.AllocSysString();

        CComBSTR bstrTemp;
        bstrTemp.Attach(bstr);

        Hack on... :) Jonathan Craig www.mcw-tech.com

        1 Reply Last reply
        0
        • B bjolletts

          Im writing a program that searches an ActiveDirectory database and want the program to take a search argument like "moderator" through a dialog window and the program will search for everyone that is a moderator. So my search function takes a CString as a parameter But to use it in the search it must be a LPWSTR (pszSearchFilter). HRESULT ExecuteSearch(LPWSTR pszSearchFilter, LPWSTR* pAttributeNames, DWORD dwNumberAttributes, PADS_SEARCH_HANDLE phSearchHandle); I havetried to builda CString that looks like this: L"(&(objectClass=user)(title=moderator))"; And then it must be converted to LPWSTR or CComBSTR or whatever that works ... any ideas how ? Thanks in advance !

          B Offline
          B Offline
          bjolletts
          wrote on last edited by
          #4

          Thanks guys, got it to work thanks to your tips !

          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