views:

234

answers:

3

I'm using managed c++ to implement a method that returns a string. I declare the method in my header file using the following signature:

String^ GetWindowText()

However, when I'm using this method from C#, the signature is:

string GetWindowTextW();

How do I get rid of the extra "W" at the end of the method's name?

+2  A: 

To get around the preprocessor hackery of the Windows header files, declare it like this:

#undef GetWindowText
String^ GetWindowText()

Note that, if you actually use the Win32 or MFC GetWindowText() routines in your code, you'll need to either redefine the macro or call them as GetWindowTextW().

Shog9
Ah, now I understand. The problem is that I'm using a header file that redefines GetWindowText() as GetWindowTextA(). I completely missed that. Thanks!
Karl
A: 

GetWindowText is a win32 api call that is aliased via a macro to GetWindowTextW in your C++ project.

Try adding #undef GetWindowText to you C++ project.

Rob Walker
A: 

Not Managed c++ but C++/CLI for the .net platform. A set of Microsoft extensions to C++ for use with their .Net system.

Bjarne Stroustrup's FAQ http://www.research.att.com/~bs/bs_faq.html#CppCLI

C++/CLI is not C++, don't tag it as such. Txs

Panic
Although this issue does apply to "old-fashioned" C++ as well, it just reveals itself differently (try exporting a function called GetWindowText from a dll and calling it through a C interface.)
Eclipse