c++-cli

c++/cli pass (managed) delegate to unmanaged code

How do I pass a function pointer from managed C++ (C++/CLI) to an unmanaged method? I read a few articles, like this one from MSDN, but it describes two different assemblies, while I want only one. Here is my code: 1) Header (MyInterop.ManagedCppLib.h): #pragma once using namespace System; namespace MyInterop { namespace ManagedCppL...

Class Library public functions are not accessible in another class library as console application

Hello, I have one class library that have all functions declared as public under public class. Still When I am going to call one of those it gives linker errors. Do I need to export these methods explicitly from class library as we export from native dll. When I export with __declspec(dllexport) it says that function cannot be exported ...

Converting C# Regex into C++/CLI?

I'm having trouble getting my C# Regex working for C++. In C# I have: //using System.Text.RegularExpressions; Regex YourName = new Regex("?<name>\w{3,16}"); but in C++ this does not correctly match: //using namespace System::Text::RegularExpressions; Regex^ rx = gcnew Regex("?<name>\w{3,16}", static_cast<RegexOptions>(RegexOption...

C++/CLI: Public ref struct generates C2011: 'class' type redefinition

Greetings! I have a header file in a managed DLL project like so: Enums.h: #pragma once ... public ref struct ManagedStruct { Bitmap^ image; } ... This header is referenced both from another class in the DLL and from a separate executable. The managed struct alone is generating error C2011: 'ManagedStruct' : 'class' type redefi...

Millisecond-Accurate Scheduling of Future Events in C++/CLI

I need to create a C++/CLI mixed assembly that can schedule future calls into a native DLL with millisecond accuracy. This will, of course, mean setting a timer (what kind?) for a millisecond or three beforehand, then spinning until the moment and calling the native DLL function. Based on what I've read, I would guess that the callba...

How to remove Thumbnail property of a JPEG image without distrubing other Exif data in C ++ .net.

I have an application which edits the metadata part of the JPEG image. I have to remove the thumbnail metadata with out disturbing other metadata. I have tried out the code below but was not successful in removing thumbnail metadata. can some help me out in solving this query thanks in advance. array<String^>^ query = gcnew array<String...

Excluding standard directories from code coverage results with C++/CLI

I have a Visual Studio 2010 .NET 4 solution with C# projects and a C++/CLI project. I use Visual Studio's built in unit tests and code coverage. Other than the fact that Visual Studio 2010 coverage tool for C++/CLI projects seems to be much weaker than Visual Studio 2008 coverage tool, I get weird results. For example, I get uncovered...

MoveFileEx Problem

int i ; DWORD dw ; String^ Source = "c:\\Program\\test.exe" ; String^ Destination = "c:\\Program Files" ; // move to program Files Folder //pin_ptr<const wchar_t> WSource = PtrToStringChars(Source); // pin_ptr<const wchar_t> WDestination = PtrToStringChars(Destination); i = MoveFileEx(L"c:\\Program Files\\Program\\Test.exe",L"c:\\Progr...

Is this the correct way to eliminate warning C4945 (symbol already imported from another assembly)?

I've got a .net solution (written in C++/CLI) which references some .dll projects as follows: MainProject->ProjectA->ProbjectB MainProject->ProjectB Originally I'd referenced both ProjectA and ProjectB from MainProject which gave me the warnings as mentioned above. I can remove the warnings by removing the reference to ProjectB from ...

Why exception occured at LoadTypeLibEx System.ArgumentException: Value does not fall within the expected range?

Hello, I am loading type library in C++/CLI. In C# its loading successfully but it's giving again and again following exception in managed C++/CLI. exception occured at LoadTypeLibEx System.ArgumentException: Value does not fall within the expected range at LoadTypeLib(String strTypeLibName, ITypeLi b typeLib) Here's a PInvoke Signat...

How can I compile some parts of C++/CLI code as Native and some part as Managed?

Hello, I am calling LoadTypeLib for loading unmanaged type libraries in C++/CLI. I need to compile some code(some code areas) as managed and some code areas as unmanaged(native) code and form a mixed mode class library as executable. What i need to mention between the lines of code so that whatever the part i need to be compiled as man...

How to call memcmp() on two parts of byte[] (with offset)?

Hi, I want to compare parts of byte[] efficiently - so I understand memcmp() should be used. I know I can using PInvoke to call memcmp() - http://stackoverflow.com/questions/43289/comparing-two-byte-arrays-in-net But, I want to compare only parts of the byte[] - using offset, and there is no memcmp() with offset since it uses pointers...

How to "pin" C++/CLI pointers

I am wrapping up a class which reading a custom binary data file and makes the data available to a .net/c# class However a couple of lines down the code, i start getting the memory access violation error which i believe is due to the GC moving memory around, the class is managed Here's the calling code in C# - reader is mixed code ( m...

New line or Carraige Return syntax problems

Im pretty new to coding, heres my problem. Results->Text = "G55 > Y" + System::Convert::ToString(destY); "Results" is a System.Windows.Forms.Textbox "multiline btw", or so says VS. That line works fine, but i need a "new line or CR" at the end, so that i can repeat that line with different Literals and a different var in ToString. F...

Linking error when referencing a C++/CLI .exe project

Hello all. I'm using VS2010 and in my solution one of my C++/CLI projects references the other. But it can only link correctly when the project being referenced is compiled as a Static Lib. I read all over that in managed .NET languages, .EXEs, libs and .dlls are the same thing, with a single flag or something like that as difference. ...

Object-oriented Programming - need your help

hey folks, I try to realize a little game project to dive deeper into OO programming (winforms c++/cli). I already started coding but now I´d like to make a re-design. For the beginning the game should consist of four parts like game-engine, user interface, highscore and playground. Heres a little (non-UML-conform) class diagramm to vi...

How to Print the contents of a textbox in C++/CLI?

I'm still learning C++ coding. I'm having troubles getting say ResultsBox->Text to printer successfully. What is the proper way to print in C++/CLI? I think im missing something simple. Ive tried multiple different routes/syntax's that ive read online/ in books. All of which got me to a dead end. Please even a rundown on the method...

What should I use to replace the WinAPI Beep() function?

I've got a Visual C++/CLI app which uses beeps to signify good and bad results (used when the user can't see the screen). Currently I use low pitched beeps for bad results and high pitched beeps for good results: if( goodResult == true ) { Beep(1000, 40); } else { Beep(2000, 20); } This works okay on my Vista laptop, but I've...

How do I convert a System::IO::Stream^ to an LPCSTR for PlaySound?

I'm trying to embed and then play back a .wav file in a C++/CLI app but all the examples I've seen which use PlaySound are in VB. I can't see how to get froma Stream^ to the LPCSTR which PlaySound requires: System::IO::Stream^ s = Assembly::GetExecutingAssembly()->GetManifestResourceStream ("Ping.wav"); LPCSTR buf = s->????; PlaySound...

Is it possible to get a pointer to String^'s internal array in C++/CLI?

The goal is to avoid copying the string data when I need a const wchar_t*. The answer seems to be yes, but the function PtrToStringChars doesn't have its own MSDN entry (it's only mentioned in the KB and blogs as a trick). That made me suspicious and I want to check with you guys. Is it safe to use that function? ...