Click here to Skip to main content
12,826,151 members (31,112 online)

Managed C++/CLI

 
GeneralRe: search in a text fiel Pin
Richard MacCutchan19-Jul-12 23:05
mvpRichard MacCutchan19-Jul-12 23:05 
QuestionConvert string to integer only such that if it is alphanumeric or float it shouldnot return anything Pin
Abinash Mohanty17-Jul-12 4:13
memberAbinash Mohanty17-Jul-12 4:13 
GeneralRe: Convert string to integer only such that if it is alphanumeric or float it shouldnot return anything Pin
John Schroedl17-Jul-12 4:29
memberJohn Schroedl17-Jul-12 4:29 
GeneralRe: Convert string to integer only such that if it is alphanumeric or float it shouldnot return anything Pin
Abinash Mohanty17-Jul-12 19:13
memberAbinash Mohanty17-Jul-12 19:13 
QuestionRead char by char in a file after write char by char to another file in vc++. Pin
lucky_122117-Jul-12 0:03
memberlucky_122117-Jul-12 0:03 
AnswerRe: Read char by char in a file after write char by char to another file in vc++. Pin
Richard MacCutchan17-Jul-12 0:32
mvpRichard MacCutchan17-Jul-12 0:32 
QuestionC++/CLI - Pin a function pointer Pin
krishter11-Jul-12 0:16
memberkrishter11-Jul-12 0:16 
GeneralRe: C++/CLI - Pin a function pointer Pin
paul_7115-Jul-12 0:51
memberpaul_7115-Jul-12 0:51 
Difficult to say from what you have shown. You can pin a handle to a managed object only temporarily, since a pin_ptr can only be created on the stack. Therefore, if you have something like this:
IntPtr YourClass::GetFuncPointer()
{
    FuncDelegate^ fp = gcnew MessageFuncDelegate(this, &Handler);
    pin_ptr<MessageFuncDelegate^> pinnedFunctionPointer = &fp;
    return ((ProcMessageFunc)pinnedFunctionPointer);
}

then you effectively have only pinned fp for the duration of this method call. A correct way to do this depends on your scenario. I'd recommend something along the lines of the following (I didn't compile it, but you get the idea):

public ref class ClientRegistrar abstract sealed {
    static FuncDelegate^ s_ManagedReceiverList;
    
    // ...
    public static void RegisterClient(YourClient^ p_Client)
    {
        // thread safety for free
        s_ManagedReceiverList += 
            gcnew MessageFuncDelegate(p_Client, &YourClient::Handler);

        // here I assume that ::Receiver is an unmanaged global function which
        // takes a funtion pointer of type ProcMessageFunc. Don't know
        // if you need to deal with multiple registrations....
        ::Receiever((ProcMessageFunc)Marshal::GetFunctionPointerForDelegate(s_ManagedReceiver));
    }

    public static void UnregisterClient(YourClient^ p_Client)
    {
        s_ManagedReceiverList -=
            gcnew  MessageFuncDelegate(p_Client, &YourClient::Handler);
        // use the same schema to unregister from the native receiver
    }
}


Usage (C#):

YourClient tClient = new YourClient();
// ...
ClientRegistrar.RegisterClient(tClient);
// ...



s_ManagedReceiverList and any YourClient instance you register via RegisterClient will be kept alive as long as the current application domain will exist. Implement UnregisterClient if you need more fine grained control. A delegate does not need to be pinned, the CLR takes care of proper handling of that. It just needs to be kept alive.

Cheers,

Paul

modified 17-Jul-12 10:14am.

QuestionHow to Make and Use Resource DialogBoxes in VC++ 2008 Pin
ICEFLOWER226-Jun-12 5:07
memberICEFLOWER226-Jun-12 5:07 
AnswerRe: How to Make and Use Resource DialogBoxes in VC++ 2008 Pin
Richard MacCutchan26-Jun-12 5:31
mvpRichard MacCutchan26-Jun-12 5:31 
GeneralRe: How to Make and Use Resource DialogBoxes in VC++ 2008 Pin
ICEFLOWER226-Jun-12 8:53
memberICEFLOWER226-Jun-12 8:53 
GeneralRe: How to Make and Use Resource DialogBoxes in VC++ 2008 Pin
Richard MacCutchan26-Jun-12 9:24
mvpRichard MacCutchan26-Jun-12 9:24 
QuestionGetting MdiParent Instance From MdiChild - Windows Forms Application Pin
Paramu197312-Jun-12 2:50
memberParamu197312-Jun-12 2:50 
AnswerRe: Getting MdiParent Instance From MdiChild - Windows Forms Application Pin
Richard MacCutchan12-Jun-12 3:15
mvpRichard MacCutchan12-Jun-12 3:15 
GeneralRe: Getting MdiParent Instance From MdiChild - Windows Forms Application Pin
Paramu197312-Jun-12 3:30
memberParamu197312-Jun-12 3:30 
GeneralRe: Getting MdiParent Instance From MdiChild - Windows Forms Application Pin
Richard MacCutchan12-Jun-12 4:03
mvpRichard MacCutchan12-Jun-12 4:03 
GeneralRe: Getting MdiParent Instance From MdiChild - Windows Forms Application Pin
Paramu197315-Jun-12 2:30
memberParamu197315-Jun-12 2:30 
QuestionHow to convert from 'WCHAR' to 'System::String ^' Managed C++ Pin
ptr_Electron7-Jun-12 21:08
memberptr_Electron7-Jun-12 21:08 
AnswerRe: How to convert from 'WCHAR' to 'System::String ^' Managed C++ Pin
Richard MacCutchan7-Jun-12 22:58
mvpRichard MacCutchan7-Jun-12 22:58 
Questionint x = (Int32) thisisObjectType is boxing, if the type is already checked ? Pin
ptr_Electron7-Jun-12 19:15
memberptr_Electron7-Jun-12 19:15 
AnswerRe: int x = (Int32) thisisObjectType is boxing, if the type is already checked ? Pin
Richard MacCutchan8-Jun-12 1:34
mvpRichard MacCutchan8-Jun-12 1:34 
QuestionVS2010 Error()- Method or Property 'VCFilter::get_Url Behavior' deprecated and nolonger implemented Pin
Paramu19737-Jun-12 0:57
memberParamu19737-Jun-12 0:57 
QuestionC++ CX and WPF Pin
Super Lloyd6-Jun-12 16:04
memberSuper Lloyd6-Jun-12 16:04 
QuestionStrong vs static typing Pin
elelont25-Jun-12 10:37
memberelelont25-Jun-12 10:37 
AnswerRe: Strong vs static typing Pin
Paul Conrad5-Jun-12 11:37
memberPaul Conrad5-Jun-12 11:37 

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.


Advertise | Privacy | Mobile
Web01 | 2.8.170326.1 | Last Updated 5 Mar 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid