Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2007

Tip: Looking for answers? Try searching our database.

VS2005 : Managed Wrapper for Unmanaged code : Ellipsis dilema

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Olivier Matrot - 17 Oct 2007 08:43 GMT
Hello,
I'm in the process of writing a managed wrapper on legacy C++ code.
I have to deal with methods that are using the ellipsis.

For instance,the legacy method is :
void CLog::Print (LPCSTR szMask, ...)
{

CHAR szText[512];

va_list arglist;

va_start (arglist, szMask);

wvsprintfA (szText, szMask, arglist);

va_end (arglist);

}

The wrapper looks like this :
void Print(System::String ^ Text, array<Object^>^ args )

{

CStringA s((LPCTSTR)UnmanagedString(Text));

m_pLog->Print(s, args);

}

I'm calling the wrapper with this call :

log->Print("Hello, CallCount is [%d]", gcnew
array<Object^>(1){(System::Int32)1});

And the result is "Hello CallCount [3226976]" instead of  "Hello CallCount
[1]"

Where is the problem ?

TIA.
adebaene@club-internet.fr - 17 Oct 2007 13:31 GMT
On Oct 17, 9:43 am, "Olivier Matrot"
<olivier.matrot....@online.nospam> wrote:
> Hello,
> I'm in the process of writing a managed wrapper on legacy C++ code.
[quoted text clipped - 24 lines]
>
> m_pLog->Print(s, args);

Here, you are passing an array<Object^>^ as the 1st ellipsis argument,
while the native part (eg, wvsprintf) expects an int. It not a
surprise it doesn't work..

I do not see any simple solution. IMHO, you should anyway get way of
those ugly, type-unsafe- c-styleish, ellipsis. You could for example
design your wrapper class to work like a stream or a StringBuilder.

Arnaud
Olivier Matrot - 17 Oct 2007 15:16 GMT
I agree with you, it is better to do the formating in managed C++.
However, I'm interrested in dealing with this for my personnal skills.
Olivier.

> On Oct 17, 9:43 am, "Olivier Matrot"
> <olivier.matrot....@online.nospam> wrote:
[quoted text clipped - 36 lines]
>
> Arnaud
David Anton - 17 Oct 2007 23:51 GMT
Why not use a C++/CLI parameter array?
e.g.,
void test(... array<System::Object^> ^ParamArray)
Signature

http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
C++ to C++/CLI
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB or C# to C++/CLI

> Hello,
> I'm in the process of writing a managed wrapper on legacy C++ code.
[quoted text clipped - 38 lines]
>
> TIA.
Olivier Matrot - 18 Oct 2007 13:43 GMT
I've changed the parameter in my code below with your suggestion. It
becomes:
void Print(System::String ^ Text, ... array<Object^>^ args )
The result is the same.

> Why not use a C++/CLI parameter array?
> e.g.,
[quoted text clipped - 43 lines]
>>
>> TIA.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.