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::S tring ^ Text, array<Object^>^ args )
{
CStringA s((LPCTSTR)Unma nagedString(Tex t));
m_pLog->Print(s, args);
}
I'm calling the wrapper with this call :
log->Print("Hello , CallCount is [%d]", gcnew
array<Object^>( 1){(System::Int 32)1});
And the result is "Hello CallCount [3226976]" instead of "Hello CallCount
[1]"
Where is the problem ?
TIA. 4 3653
On Oct 17, 9:43 am, "Olivier Matrot"
<olivier.matrot ....@online.nos pamwrote:
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::S tring ^ Text, array<Object^>^ args )
{
CStringA s((LPCTSTR)Unma nagedString(Tex t));
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******@clu b-internet.frwrot e in message
news:11******** **************@ v29g2000prd.goo glegroups.com.. .
On Oct 17, 9:43 am, "Olivier Matrot"
<olivier.matrot ....@online.nos pamwrote:
>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::S tring ^ Text, array<Object^>^ args )
{
CStringA s((LPCTSTR)Unma nagedString(Tex t));
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::O bject^^ParamArr ay)
-- 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::S tring ^ Text, array<Object^>^ args )
{
CStringA s((LPCTSTR)Unma nagedString(Tex t));
m_pLog->Print(s, args);
}
I'm calling the wrapper with this call :
log->Print("Hello , CallCount is [%d]", gcnew
array<Object^>( 1){(System::Int 32)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::S tring ^ Text, ... array<Object^>^ args )
The result is the same.
"David Anton" <Da********@dis cussions.micros oft.comwrote in message
news:85******** *************** ***********@mic rosoft.com...
Why not use a C++/CLI parameter array?
e.g.,
void test(... array<System::O bject^^ParamArr ay)
-- 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::S tring ^ Text, array<Object^>^ args )
{
CStringA s((LPCTSTR)Unma nagedString(Tex t));
m_pLog->Print(s, args);
}
I'm calling the wrapper with this call :
log->Print("Hello , CallCount is [%d]", gcnew array<Object^> (1){(System::In t32)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 constructor, it is returning undefined. Here is an
example:
Unmanaged C++
class Map_Interface
|
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. The guts will remain in unmanaged
c++. So I need to write public managed c++ wrapper classes for the couple
of interfaces the unmanaged stuff needs to expose for the GUI.
Questions:
|
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 Initialize function in the unmanaged
library) crashes everytime I call it. Initialize calls another function
'GetInstance' (a static member function of a class) which looks something
like:
CLibConfig& CLibConfig::GetInstance()
|
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 work with my code. I
have a VB Net front end which need the access the unmanaged functions. The
wrapper I wrote can be accessed but the wrapper will not compile when I
refer to the unmanaged class. I have tried using header file for definitions...
|
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 managed wrapper around an unmanaged range class. Vector is a managed wrapper around an unmanaged vector class. Cell is a managed wrapper around an unmanaged cell class.
Here r returns a managed Vector* and r accesses a particular Cell in the Vector.
| |
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 write a wrapper between unmanaged API and
my managed app.
Now on to the question:
If there's an unmanaged API class called X with a defined method
|
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 some specific things..
for example, I have unmanaged class
class Foo
{
void SetData(std::map<std::string, std::stringsvalue);
};
|
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 this, I want to use
it. Is it possible to call Managed class functions from Unmanaged
class? How to do it?
I did something like this.
I declared a managed class (in C++ CLI) called as MyManagedClass whose
|
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 3rd party unmanaged DLL will pass this
reference into standard Win32 unmanaged static callback function in my code.
Inside this unmanaged callback function I need to cast this unmnaged pointer
that I have received from 3rd party back into the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |