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

Managed C++/CLI

 
Questionreal time matrix conversion Pin
Morad Kobi13-Aug-07 4:02
Morad Kobi13-Aug-07 4:02 
AnswerRe: real time matrix conversion Pin
Luc Pattyn13-Aug-07 5:51
sitebuilderLuc Pattyn13-Aug-07 5:51 
QuestionRe: real time matrix conversion Pin
George L. Jackson13-Aug-07 13:58
George L. Jackson13-Aug-07 13:58 
QuestionAccess controls from other modules of a program Pin
eugk12-Aug-07 23:31
eugk12-Aug-07 23:31 
AnswerRe: Access controls from other modules of a program Pin
mid=574113-Aug-07 5:38
mid=574113-Aug-07 5:38 
GeneralRe: Access controls from other modules of a program Pin
eugk13-Aug-07 8:40
eugk13-Aug-07 8:40 
GeneralRe: Access controls from other modules of a program Pin
mid=574113-Aug-07 9:12
mid=574113-Aug-07 9:12 
GeneralRe: Access controls from other modules of a program Pin
eugk13-Aug-07 12:02
eugk13-Aug-07 12:02 
Thanks, the book I am working with now is "Pro Visual C++/CLI" by Stephen Fraser, but I will look into the book you recommend too.

I see, I guess I am trying to use pFunc() in the managed code itself. But you know, it actually works if I call pFunc() right at the end of the Form constructor. I get a warning message box that it is unsafe to call function pointers from managed code, but when I click "Continue" the pFunc() is actually called, it does its work and returns properly. However, if I call pFunc() from the Button handler of the Form or from elsewhere the project does not even build:

public:
    Form1(void)
    {
        InitializeComponent();

        MyFormMethod^ m = gcnew MyFormMethod(this, &Form1::MyMethod); // create instance of my delegate.
        IntPtr pint = Marshal::GetFunctionPointerForDelegate (m); // get the pointer my method.
        PFUNC pFunc = (PFUNC)pint.ToPointer (); // save it in the global pointer.
        <code>pFunc();                   // works.</code>
    }

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        <code>pFunc();                   // does not link, unresolved external pFunc.</code>
}


It's a good point about m garbage collected at some point. Although it should be OK since I only needed it at the time I extracted pointer out of it. Then the pointer is stored in pFunc, which is global and should not get deallocated.

By the way, should we be even talking about calls between managed/unmanaged code here? My test app in my example is just a plain WinFormsApp "Hello World" example (should be all "managed") with a few mods: I put function foo() in my WinFormsApp.CPP with the code to access something on the form (in Form1.h), say a textBox. I press the button to call foo() and foo() writes some text, that's it. I cannot use Form1::textBox::Text = "Text" in foo(), I tried to create a new public method in my Form that does this->textBox->Text = "Text", but the compiler says "cannot access a non-static member". OK, I make my method static but then I cannot access the textBox from it anymore: error C2597: illegal reference to non-static member 'System::Windows::Forms::Form::Text'.

Of course, I will keep reading and searching for the example that does exactly what I am trying to do, but the solution to my problem should be very simple. Maybe it is so simple that they do not explain it in the books. If someone could just tell me what I am missing...

Thanks!
Eugene
GeneralRe: Access controls from other modules of a program [modified] Pin
mid=574113-Aug-07 12:35
mid=574113-Aug-07 12:35 
GeneralRe: Access controls from other modules of a program Pin
eugk13-Aug-07 15:52
eugk13-Aug-07 15:52 
GeneralRe: Access controls from other modules of a program [modified] Pin
mid=574113-Aug-07 16:12
mid=574113-Aug-07 16:12 
GeneralRe: Access controls from other modules of a program Pin
eugk13-Aug-07 20:26
eugk13-Aug-07 20:26 
QuestionWhat makes a class IDisposable? Pin
mid=574111-Aug-07 15:19
mid=574111-Aug-07 15:19 
AnswerRe: What makes a class IDisposable? Pin
Mark Salsbery12-Aug-07 7:30
Mark Salsbery12-Aug-07 7:30 
GeneralRe: What makes a class IDisposable? Pin
mid=574112-Aug-07 7:58
mid=574112-Aug-07 7:58 
GeneralRe: What makes a class IDisposable? Pin
Luc Pattyn12-Aug-07 8:41
sitebuilderLuc Pattyn12-Aug-07 8:41 
GeneralRe: What makes a class IDisposable? [modified] Pin
mid=574112-Aug-07 9:00
mid=574112-Aug-07 9:00 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 6:06
iddqd51513-Aug-07 6:06 
GeneralRe: What makes a class IDisposable? Pin
mid=574113-Aug-07 6:15
mid=574113-Aug-07 6:15 
GeneralRe: What makes a class IDisposable? Pin
led mike13-Aug-07 6:28
led mike13-Aug-07 6:28 
GeneralRe: What makes a class IDisposable? Pin
mid=574113-Aug-07 6:46
mid=574113-Aug-07 6:46 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 6:29
iddqd51513-Aug-07 6:29 
GeneralRe: What makes a class IDisposable? Pin
mid=574113-Aug-07 6:45
mid=574113-Aug-07 6:45 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 7:32
iddqd51513-Aug-07 7:32 
GeneralRe: What makes a class IDisposable? Pin
mid=574113-Aug-07 7:53
mid=574113-Aug-07 7:53 

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.