Posts filed under 'From 2003 to 2008'

Passing value types by reference (a ref keyword) to the managed C++ (CLI)

Hi, after a little research I did to accomplish this task, I thought it would be nice to share the solution with my readers, so here it is: in the CLI method you should use a “%” keyword, it is the same as “ref” in the C#.

Example: (passing integer by ref from C# to CLI)

declaring method in the CLI:  
MyClass::MyMethod(Int32% myValue);

calling that method from C#:
MyClass myClass = new MyClass();
int myValue = 12;
myClass.MyMethod(ref myValue);

 

Hope that was helpful,
Evgeni

Add comment November 26, 2008

Error Link2028: unresolved token

Yesterday during convertion of some C++ project from VS2003 to VS2008, I had error ‘Link2028′ during linking. In other  circumstances I would sure I missing function body which I was declared in .h file. However, this project was perfectly building in VS2003. Here is how I solved this: in project properties, locate C/C++ \CommandLine. I removed /Zl switch, and that was worked for me)

Add comment February 4, 2008

Converting CString to integer (VS 2005)

Well, today I got another reason to abandon MFC (this one added to very long list I already have). Consider this very simple task: convertion of CString to integer. Is can something be more basic than this?? Doing this in .NET takes, in worst case, 5 seconds? I took me about a hour to discover how to do that in MFC. In the VS 2003, the following code does works:

CString someText;
int value = atoi(someText);

However, in VS 2005 it doesn’t. atoi function assepts only const char*, and if you casting CString to const char*, you got only first digit of the number. Finally, I found some solution (God bless Internet) that works:

CString someText;
int value = _ttoi(static_cast<LPCTSTR>(someText));

I don’t know, how an average programmer supposed to discover this on his own. From my own experience, I saw string representation in about 10 different forms (in c++, ofc), and this is not trivial at all to convert from one form to other. Pfff…

6 comments January 14, 2008


Categories

Top Posts

Tags

.NET addin app.config ArrayList bug CAB Configuration ConfigurationManager ConfigurationSection ContentControl ContextMenu CTime; DateTime custom keys DataBinding DataContext Data templates debugging equals gethashcode GUI Hashtable interlocked Invoke lock lock free memcpy MFC multithreading multithreading; lock free override performance SCSF serialization Smart Client Software Factory Styles System.Configuration unsafe virtual functions Visual Studio wait free WinAPI WinForms WinForms\WPF Integration World of Warcraft World of Warcraft; Addon

Archives