Click here to Skip to main content
15,891,657 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionStatic and Global Variables? Pin
VonHagNDaz19-May-11 3:08
VonHagNDaz19-May-11 3:08 
AnswerRe: Static and Global Variables? Pin
Mark Salsbery19-May-11 8:28
Mark Salsbery19-May-11 8:28 
QuestionDateTime->Parse Pin
VonHagNDaz16-May-11 4:34
VonHagNDaz16-May-11 4:34 
AnswerRe: DateTime->Parse [modified] Pin
Mark Salsbery16-May-11 7:26
Mark Salsbery16-May-11 7:26 
GeneralRe: DateTime->Parse Pin
VonHagNDaz16-May-11 10:56
VonHagNDaz16-May-11 10:56 
GeneralRe: DateTime->Parse Pin
Mark Salsbery16-May-11 12:57
Mark Salsbery16-May-11 12:57 
GeneralRe: DateTime->Parse Pin
VonHagNDaz17-May-11 1:57
VonHagNDaz17-May-11 1:57 
Question[C++/CLI]problem with unmanaged C library and callback functions Pin
re dei giovani16-May-11 3:39
re dei giovani16-May-11 3:39 
Hi,
I've got this problem and I don't try to solve it.
I'm using Microsoft Studio 2008 and I want to build a managed application.
This application uses a C unmanaged library.

In particular the library function that I must use is:

error_status TED_PixRad_RegisterEventCallback( eventCallback_t eventCallbackProc,void* customData = NULL ).
(I must use it to hook the event returned by a device).

This function has a callback function parameter with this syntax:

typedef void (*eventCallback_t)( const event_id eventID, const Event *eventData,void* customData );

I' ve found that I must build a wrapper class to use my managed application and the unmanaged library.

I try to build a wrapper class:

file wrapper.h:
#pragma once
#include "stdafx.h"
#include "gcroot.h"

namespace Pixium {

using namespace System;
using namespace System::Runtime::InteropServices;

void cdeclEventCallback(const event_id eventID, const Event *eventData, void* customData );

public ref class Library
{
public:
delegate void eventRegistered(const event_id eventID);

internal:

eventRegistered ^_event_registered;
private:

gcroot<Library^> *_native_handle;
public:
Library();
~Library();
error_status registerEvent(eventRegistered ^evento);
};
}

file wrapper.cpp:
#include "stdafx.h"
#include "wrapper.h"

namespace Pixium {
Library::Library()
{
_native_handle = new gcroot<Library^>();
_event_registered=nullptr;
}
Library::~Library()
{
delete _native_handle;
}
error_status Library::registerEvent(eventRegistered ^evento)
{
_event_registered=evento;
return TED_PixRad_RegisterEventCallback(cdeclEventCallback,_native_handle);
}

void cdeclEventCallback(const event_id eventID, const Event *eventData, void* customData )
{
gcroot<Library^> & native_handle = *((gcroot<Library^>*)customData);
native_handle->_event_registered(eventID);
}
}

In an application class I try to use this wrapper to receive the values event returned.

In particular in the constructor I initialize the wrapper object:
Form1(void)
{
InitializeComponent();
this->lib=gcnew Library(); //istanzio il wrapper
//event_registered= gcnew Library::eventRegistered(this,&Form1::processEvent);
this->registerEvent();
}

and in the function I call a wrapper event register funciotn:

void Form1::registerEvent()
{
//error_status err_reg_event=TED_PixRad_RegisterEventCallback((eventCallback_t)Marshal::GetFunctionPointerForDelegate(del).ToPointer(),_native_handle);
error_status err_reg_event=this->lib->registerEvent(); //utilizzo il wrapper
if (this->TestError(err_reg_event)){
this->button2->Visible=true;
}
}


The problem: I think a mistake to use the wrapper by my application or also in wrapper building.
Infact I' ve got error on the callback function when I try to receive event message.

I apologize for my bad English, hoping to be able to explain problem

Someone can indicates me an example or tutorial to learn how can I work with managed C++/CLI and unmanaged C type?
Thanks
AnswerRe: [C++/CLI]problem with unmanaged C library and callback functions Pin
John Schroedl16-May-11 5:22
professionalJohn Schroedl16-May-11 5:22 
GeneralRe: [C++/CLI]problem with unmanaged C library and callback functions Pin
re dei giovani17-May-11 3:27
re dei giovani17-May-11 3:27 
GeneralRe: [C++/CLI]problem with unmanaged C library and callback functions Pin
re dei giovani17-May-11 3:55
re dei giovani17-May-11 3:55 
AnswerRe: [C++/CLI]problem with unmanaged C library and callback functions Pin
Luc Pattyn17-May-11 4:22
sitebuilderLuc Pattyn17-May-11 4:22 
GeneralRe: [C++/CLI]problem with unmanaged C library and callback functions Pin
re dei giovani18-May-11 2:15
re dei giovani18-May-11 2:15 
AnswerRe: [C++/CLI]problem with unmanaged C library and callback functions Pin
Luc Pattyn18-May-11 2:46
sitebuilderLuc Pattyn18-May-11 2:46 
QuestionChanging a C++/CLI project from static lib to DLL causing app to crash under Win7 but works under WinXP Pin
TrevorPT13-May-11 7:20
TrevorPT13-May-11 7:20 
AnswerRe: Changing a C++/CLI project from static lib to DLL causing app to crash under Win7 but works under WinXP Pin
John Schroedl13-May-11 11:01
professionalJohn Schroedl13-May-11 11:01 
GeneralRe: Changing a C++/CLI project from static lib to DLL causing app to crash under Win7 but works under WinXP Pin
TrevorPT13-May-11 11:59
TrevorPT13-May-11 11:59 
GeneralRe: Changing a C++/CLI project from static lib to DLL causing app to crash under Win7 but works under WinXP Pin
John Schroedl13-May-11 14:31
professionalJohn Schroedl13-May-11 14:31 
GeneralRe: Changing a C++/CLI project from static lib to DLL causing app to crash under Win7 but works under WinXP Pin
TrevorPT16-May-11 11:19
TrevorPT16-May-11 11:19 
AnswerRe: Changing a C++/CLI project from static lib to DLL causing app to crash under Win7 but works under WinXP Pin
jschell13-May-11 12:32
jschell13-May-11 12:32 
AnswerRe: Changing a C++/CLI project from static lib to DLL causing app to crash under Win7 but works under WinXP Pin
TrevorPT17-May-11 6:12
TrevorPT17-May-11 6:12 
QuestionPassing an ArrayList by Reference? [modified] Pin
VonHagNDaz13-May-11 2:39
VonHagNDaz13-May-11 2:39 
AnswerRe: Passing an ArrayList by Reference? Pin
John Schroedl13-May-11 3:29
professionalJohn Schroedl13-May-11 3:29 
GeneralRe: Passing an ArrayList by Reference? Pin
VonHagNDaz13-May-11 4:15
VonHagNDaz13-May-11 4:15 
QuestionTimer() - anything faster? Pin
Cyclone_S12-May-11 10:47
Cyclone_S12-May-11 10:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.