none
How to pass a character array by tracking reference RRS feed

  • Question

  • I have an unmanaged COM object that I converted to a .NET wrapper using Tlbimp.exe so I could use it with a CLR C++ console application. The prototype for 'GetCOMServerNameAndVersion(signed char %name, float %version)'.

    1) How do i pass a character array by tracking reference(%)? The example below fails to compile resulting in "cannot convert parameter 1 from 'char' to 'signed char %' "
    2) Perhaps there's an easier way to declare my class thus gaining access to my methods. Any suggestions here would be appreciated as well.

    using namespace System;
    using namespace COMSERVERLib;
    
    int main(array<System::String ^> ^args)
    {	
    
    	COMSERVERLib::DataClass ^ m_pIData;
    	m_pIData = gcnew COMSERVERLib::Data;
    
    	int nGroups;
    	int nItems;
    	char nName[100];
    	float fVersion;
    
    
    	m_pIData->GetNumberOfGroups(nGroups );
    	m_pIData->GetNumberOfDataItems(0,nItems);
    	m_pIData ->GetCOMServerNameAndVersion(nName, &fVersion);
    
    	Console::WriteLine("The number of groups is "+ nGroups.ToString() + " and items is " + nItems.ToString());
    	Console::ReadKey();
        return 0;
    }
    Thank You,
    Craig
    Wednesday, November 25, 2009 10:02 PM

Answers

  • Why do you need managed wrapper for your COM object? Why don't you use it directly from your VC++ code?

    Also what is the original signature of your native method 'GetCOMServerNameAndVersion(signed char %name, float %version)'? Because the 'signed char %' is a tracking reference to a single signed character. That is most likely not what the native COM object returns (name - array of chars). IMO either tlbimp.exe didn't do a good job here, or the TLB has wrong type information.

    -Karel
    • Marked as answer by cme0848 Sunday, December 20, 2009 6:59 PM
    Tuesday, December 1, 2009 12:39 AM
    Moderator

All replies

  • Hello

    For COM interface, it's recommended to expose string parameters as BSTR, instead of char*. If you owns the COM server, please see if it's possible to make this change.


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, November 26, 2009 1:22 PM
    Moderator
  • Unfortunantely my challenge is to interface with the legacy code as is. :-/. Also, since this is a release version of the COM server any changes to the code would not benefit the legacy users.

    I'll keep working on it but if anyone stumbles onto this thread let me know if there's an easier way to use this COM. I even thought it would make my life easier by reverting to VS 6.0. Any thoughts?

    Craig
    Monday, November 30, 2009 4:08 AM
  • Why do you need managed wrapper for your COM object? Why don't you use it directly from your VC++ code?

    Also what is the original signature of your native method 'GetCOMServerNameAndVersion(signed char %name, float %version)'? Because the 'signed char %' is a tracking reference to a single signed character. That is most likely not what the native COM object returns (name - array of chars). IMO either tlbimp.exe didn't do a good job here, or the TLB has wrong type information.

    -Karel
    • Marked as answer by cme0848 Sunday, December 20, 2009 6:59 PM
    Tuesday, December 1, 2009 12:39 AM
    Moderator
  • Hello Craig

    How are you? Do you have any updates about this issue? Could you please follow up with Karel's queries?


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, December 17, 2009 7:24 AM
    Moderator
  • Karel,

    That's a very good point. I guess I was thinking that Tlbtimp.exe would do all the heavy lifting and then I could just access the assembly easily using .NET. You've offerred the most reasonable and straight forward approach which is to Access the native COM and make a wrapper the old fashion (and right) way.

    I will get back to this tread when I have results.

    The orginal prototype is...
    GetCOMServerNameAndVersion(sbyte name[],float *version)

    Sincerely,
    Craig

    Sunday, December 20, 2009 6:59 PM