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. 4 3635
On Oct 17, 9:43 am, "Olivier Matrot"
<olivier.matrot....@online.nospamwrote:
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);
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
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.
<ad******@club-internet.frwrote in message
news:11**********************@v29g2000prd.googlegr oups.com...
On Oct 17, 9:43 am, "Olivier Matrot"
<olivier.matrot....@online.nospamwrote:
>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);
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
Why not use a C++/CLI parameter array?
e.g.,
void test(... array<System::Object^^ParamArray)
-- 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
"Olivier Matrot" wrote:
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.
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.
"David Anton" <Da********@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
Why not use a C++/CLI parameter array?
e.g.,
void test(... array<System::Object^^ParamArray)
-- 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
"Olivier Matrot" wrote:
>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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JRoe |
last post by:
Hello,
I am beside myself with this problem.
I need to access unmanged C++ code in a C# environment. I have created
a managed C++ wrapper that wraps the unmanaged class.
When I call the...
|
by: Eric Twietmeyer |
last post by:
Hello,
I'm starting to investigate cs, managed c++ and interoperating with a very
large unmanaged code base. We are going to use Windows Forms (written in
cs) to replace our old fashioned GUI. ...
|
by: Adam Clauss |
last post by:
I have an unmanaged C++ library that I need to use through C#. I created a
Managed C++ class library and through it wrote a wrapper class to call what
I need.
However, one of the methods (an...
|
by: Brett Styles |
last post by:
Hi Guys,
I am trying to access a class in an unmanaged dll. I have
created a wrapper managed class to access the functions I need but no matter
what I try from the MSDN samples I can not get it to...
|
by: DotNetJunkies User |
last post by:
Background:
I am creating a VC++ .NET wrapper for a C++ DLL; the aim is to use this wrapper in C# as shown below:
Range r = new Range( 2, 2 );
r = new Cell( “Hello Mum” );
Range is a...
|
by: Tommy Svensson \(InfoGrafix\) |
last post by:
I've been instructed to work againt a huge unmanaged C++ API from a C#
application.
Now, the only way, as I've understood it, is to go the Managed Extensions
for C++ way. This means I have to...
|
by: devmentee |
last post by:
I want to write a managed wrapper( kind of proxy) which will call into
unmanaged C++ code.
I've got a general idea and have read some articles on how to do it.
But I cannot find any information on...
|
by: Amit Dedhia |
last post by:
Hi All
I have a VC++ 2005 MFC application with all classes defined as
unmanaged classes. I want to write my application data in xml format.
Since ADO.NET has buit in functions available for...
|
by: =?Utf-8?B?RWR3YXJkUw==?= |
last post by:
I would greatly appreciate some help on passing managed object into unmanaged
code.
I need to pass a reference (address of) of a managed class into unmanaged
code (written by a thrid party). The...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |