void Nish(char* szBlog);

Nish’s thoughts on MFC, C++/CLI and .NET

void Nish(char* szBlog); header image 4

Entries from September 2004

Using reflection to invoke private methods

September 23rd, 2004 · 7 Comments

Here’s some sample code showing how you can do this; the example calls System::String::InternalLength which is private. Console::WriteLine(safe_cast<int>( __typeof(String)->InvokeMember(“InternalLength”, BindingFlags::InvokeMethod | BindingFlags::NonPublic | BindingFlags::Instance, nullptr,gcnew String(“hello world”), gcnew array<Object^>(0)))); Of course, in the above case what we did is not particularly useful since we could simply have used the Length property which internally calls InternalLength, [...]

[Read more →]

Tags: C++/CLI · CLR/.NET BCL

Instantiating a generic type parameter in C++/CLI

September 18th, 2004 · 10 Comments

I was working on some code and encountered an annoying problem with generics in C++/CLI. See the following code :- generic<typename T> where T:Base ref class Test { public: Test() { T t = gcnew T(); // won’t compile t->Hello(); } }; It won’t compile You get this error message :- C3227: ‘T’ : cannot [...]

[Read more →]

Tags: C++/CLI

Tracking References

September 2nd, 2004 · 7 Comments

The last couple of blog entries I made were on native C++ references and I thought maybe it’s a good time to talk about tracking references in C++/CLI. The punctuator used to specify a tracking reference is % (similar to & for a native reference). See the code snippet below :- void ChangeString(String^ str) { [...]

[Read more →]

Tags: C++/CLI