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. how to use char* in ATL

how to use char* in ATL

Scheduled Pinned Locked Moved ATL / WTL / STL
c++csharpvisual-studiocomsysadmin
4 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.
  • Y Offline
    Y Offline
    yingkou
    wrote on last edited by
    #1

    I am learning Program COM by ATL,I build a inpro-server dll and add a com object ComputerInfo,I only add a method to IComputerInfo and not to any thing just as bellow: interface IComputerInfo : IDispatch { [id(1), helpstring("method Test")] HRESULT GetCPU(char* bufName,const int* size); }; STDMETHODIMP CComputerInfo::GetCPU(char* bufName,const int* size) { // TODO: Add your implementation code here return S_OK; } Compiler shows: ATLFirst.cpp error C2259: 'CComObject' : cannot instantiate abstract class due to following members: atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator >::CreateInstance(void *,const struct _GUID &,void ** )' f:\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : warning C4259: 'long __stdcall IComputerInfo::GetCPU(unsigned char *,const int *)' : pure virtual function was not defined if I have change the metho to GetCPU(unsigned char* bufName,const int* size) all right,it works well,why???

    G 1 Reply Last reply
    0
    • Y yingkou

      I am learning Program COM by ATL,I build a inpro-server dll and add a com object ComputerInfo,I only add a method to IComputerInfo and not to any thing just as bellow: interface IComputerInfo : IDispatch { [id(1), helpstring("method Test")] HRESULT GetCPU(char* bufName,const int* size); }; STDMETHODIMP CComputerInfo::GetCPU(char* bufName,const int* size) { // TODO: Add your implementation code here return S_OK; } Compiler shows: ATLFirst.cpp error C2259: 'CComObject' : cannot instantiate abstract class due to following members: atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator >::CreateInstance(void *,const struct _GUID &,void ** )' f:\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : warning C4259: 'long __stdcall IComputerInfo::GetCPU(unsigned char *,const int *)' : pure virtual function was not defined if I have change the metho to GetCPU(unsigned char* bufName,const int* size) all right,it works well,why???

      G Offline
      G Offline
      geo_m
      wrote on last edited by
      #2

      I think this is a problem (bug?) in the IDL compiler, that generated the unsigned char* signature instead the char* Anyway, if you want to be able to call your component from e.g. Visual Basic or something, it's better to use BSTR type for strings. This is basically counted unicode string (Basic STRing). Then you can cope with that using helper classes CComBSTR from ATL or _bstr_t from comdef.h Hope this helps

      Y 1 Reply Last reply
      0
      • G geo_m

        I think this is a problem (bug?) in the IDL compiler, that generated the unsigned char* signature instead the char* Anyway, if you want to be able to call your component from e.g. Visual Basic or something, it's better to use BSTR type for strings. This is basically counted unicode string (Basic STRing). Then you can cope with that using helper classes CComBSTR from ATL or _bstr_t from comdef.h Hope this helps

        Y Offline
        Y Offline
        yingkou
        wrote on last edited by
        #3

        thanks a lot.and I also have a question. unsigned char buf[]="hello";//OK strcpy(buf,"hello");//Error:because buf is not char* and if I forced buf to char* and use MessageBox to show it,I found many rubbish code.I don't know the advantage of the unsigned char*,could you tell me?

        G 1 Reply Last reply
        0
        • Y yingkou

          thanks a lot.and I also have a question. unsigned char buf[]="hello";//OK strcpy(buf,"hello");//Error:because buf is not char* and if I forced buf to char* and use MessageBox to show it,I found many rubbish code.I don't know the advantage of the unsigned char*,could you tell me?

          G Offline
          G Offline
          geo_m
          wrote on last edited by
          #4

          unsigned char is in equal to BYTE type from windows header. Difference between these is stated in the name of the type - both are 1 byte of size, but char is signed and unsigned char is... unsigned (unless you switch the C++ compiler to treat char as unsigned). because in C++ the type checking is quite strict, you cannot implicitly convert unsigned to signed and vice versa. You have to state explicitly, that you really want to do it. (e.g. by casting) Just an advice - don't use the strcpy and similar functions. Find and stick to some string wrapper - be it std::string from stl libraries or CString from MFC/ATL. This would save you lot of troubles when looking for bugs inside string manipulation (forgotten ending \0, buffer overruns or whatever)

          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