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#
  4. How to Interop 2D char in c#

How to Interop 2D char in c#

Scheduled Pinned Locked Moved C#
c++comcsharpdata-structureshelp
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.
  • P Offline
    P Offline
    platso_588
    wrote on last edited by
    #1

    I have written a COM DLL which gives the out parameter as BSTR**(Typically 2D Char Array). This COM function will fill the values of BSTR** variable. I am able to use this function sucessfully in MFC Application. But I face problem in using it in C#. The Sample code is as follows: ///////////COM Function//////////////////////////////////////// STDMETHODIMP CSampleTest::GetAllDeviceList2(BSTR** szMaclist) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); for(int i=0;i<10;i++) { szMaclist[i] = new BSTR[100]; wchar_t *szTmp = new wchar_t[100]; wsprintf(szTmp,L"Device%d",i+1); *szMaclist[i]=SysAllocString(szTmp); } return S_OK; } /////////////////////////////////////////////////////////////// I acessed this in VC++ by, BSTR **szMaclist = new BSTR*[10]; CoInitialize(NULL); HRESULT hr = CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,iid,(void**)&pText); if( SUCCEEDED(hr) ) { pText->GetAllDeviceList2(szMaclist); pText->Release(); } and i am sucessful in acessing this function in MFC Application. Can anyone tell me how to acess GetAllDeviceList2() function in c#.

    M 1 Reply Last reply
    0
    • P platso_588

      I have written a COM DLL which gives the out parameter as BSTR**(Typically 2D Char Array). This COM function will fill the values of BSTR** variable. I am able to use this function sucessfully in MFC Application. But I face problem in using it in C#. The Sample code is as follows: ///////////COM Function//////////////////////////////////////// STDMETHODIMP CSampleTest::GetAllDeviceList2(BSTR** szMaclist) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); for(int i=0;i<10;i++) { szMaclist[i] = new BSTR[100]; wchar_t *szTmp = new wchar_t[100]; wsprintf(szTmp,L"Device%d",i+1); *szMaclist[i]=SysAllocString(szTmp); } return S_OK; } /////////////////////////////////////////////////////////////// I acessed this in VC++ by, BSTR **szMaclist = new BSTR*[10]; CoInitialize(NULL); HRESULT hr = CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,iid,(void**)&pText); if( SUCCEEDED(hr) ) { pText->GetAllDeviceList2(szMaclist); pText->Release(); } and i am sucessful in acessing this function in MFC Application. Can anyone tell me how to acess GetAllDeviceList2() function in c#.

      M Offline
      M Offline
      Moim Hossain
      wrote on last edited by
      #2

      Generate a COM Class Wrapper (CCW)[^] then add reference to that in your .net project and invoke. Probably you will get a 2D array of object (i.e. object[][] ) for that BSTR**.

      Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV

      P 1 Reply Last reply
      0
      • M Moim Hossain

        Generate a COM Class Wrapper (CCW)[^] then add reference to that in your .net project and invoke. Probably you will get a 2D array of object (i.e. object[][] ) for that BSTR**.

        Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV

        P Offline
        P Offline
        platso_588
        wrote on last edited by
        #3

        If you don't mind could you please provide me the code snippet for the above.

        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