|
i have array with 5 declerated items, but i wan't to add another.
I don't want to execute the code twice, yust first for count to see how many declerations is needed, secund time to declare array with n items, as counted before.
I don't like to use another array as predefine, to backup and redeclare first array with index+1 and then copy from temp array back.
I know it is possible in managed c++, but i am using c++/cli (With .NET framework 2.0) and i don't wan't to use with compiler /cli:old
|
|
|
|
|
Use the 'Resize' method of the Array class.
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter, VB to C++ converter
Instant Python: VB to Python converter
|
|
|
|
|
Thanks, I yust needed that.
|
|
|
|
|
Hello,
I’m trying to send delegate to unmanaged code, so when the unmanaged class will catch an event it will execute the proper function in the managed class.
I used GCHandle::Alloc() to prevent from the GC to change the position on the heap and
Marshel::GetFunctionPointerForDelegate()to convert the delegate to unmanaged function pointer.
The main problem is that an error occurred while I tries to execute the function pointer in the unmanage code to the managed code I get that error.
“
Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'D:\Dev\Test_TA.exe'.
Additional Information: The runtime has encountered a fatal error. The address of the error was at 0x79f1c189, on thread 0x910. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
“
Did anyone encounter this problem?
Is it a problem with the Marshel::GetFunctionPointerForDelegate()? Or with the GC?
Thanks,
|
|
|
|
|
|
Hi,
Thanks for your reply.
I already try that before, but it my case the program structure is little different.
The problem is that the program has 2 phases:
1. Managed class creates a delegate and sends it to unmanaged class which assigns it to a function pointer member.
2. The unmanaged class listens to events from other place and when a specific event occurred then the unmanaged class should call the function in the managed class.
(From the first phase)
Maybe there is no different between cases but I still get this error.
Thank you,
|
|
|
|
|
This is almost same case. The only difference that EnumWindows calls managed callback number of times inside of method, and keeping local delegate instance is enough. In your case you need to keep delegate as class member.
I think the problem is in function prototype. What is required unmanaged prototype and managed callback prototype?
In my program I use another method for managed callback - because I didn't know about this Marshal function when started to write it. Code fragments:
GCHandle gcHandle; // managed class member
// Constructor:
gcHandle = GCHandle::Alloc(this);
void* callbackPtr = GCHandle::ToIntPtr(gcHandle).ToPointer();
pUnmanagedClass->SetCallbackAddress(callbackPtr);
// Destructor:
gcHandle.Free();
Pass callbackPtr value to unmanaged class. This is simple unmanaged void* pointer, which allows to call managed class function when necessary.
// Unmanaged class calls managed class:
GCHandle h = GCHandle::FromIntPtr(IntPtr(callbackPtr)); // callbackPtr is passed from managed class
YourManagedClass^ pThis = (YourManagedClass^)h.Target;
pThis->CallbackFunction();
|
|
|
|
|
I still get the error
Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'D:\Dev\Test_TA.exe'.
Additional Information: The runtime has encountered a fatal error. The address of the error was at 0x79f1c189, on thread 0x910. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
This error ocured when the function pointer in the unmanaged code call
to the function in the managed code.
In the managed code I uesd GCHandle::Aloc(this).
thanks
|
|
|
|
|
I'm sure that this is a stupid question and that I am just missing some obvious but here it goes.
I'm adding a remoting interface to an MFC service that I have. I've gotten it to compile and run with the CLI and now I'm porting the COM interface to a remoting interface.
Then I hit a problem.
I have some methods that return values as parameters..you know the old "BOOL *" and the ever popular "LPTSTR *"....anyway... in C++/CLI these get translated to Boolean * and String^ *.
the problem is...HOW in the world do I call these from C#? I know it's a reference, but c++/cli doesn't support the keyword REF and c# doesn't like things like "&".
I guess I could try to jump thru a lot of hoops and get it to work via unmanaged code, but this SEEMS like a simple syntax problem.
sorry again to bother people with this, but for the life of me...I can't find the "right" keywords to get google to show me what I need.
thanks,
Gene
|
|
|
|
|
Do you want to call String from c# to MFC or to c++/cli
If you chose c++/cli, yust add a project to your solution, and add a reference.
|
|
|
|
|
What I'm trying to do is call the C++/cli from C#. The method I'm calling is trying to return an out parameter like String^ *. It would be a "ref" in c# and a & in normal C++.
I did figure it out though. the magic symbol is %. it looks like % means ref in C++/CLI.
|
|
|
|
|
Let's say you have a class in C#.
And both project are under your solution.
Go to c++/cli project setting, and add a reference by projects, and select a project c#.
When in c++/cli:
using namespace projectCSharNamespace;
projectCSharpClass ^cl = gcnew projectCSharpClass();
cl->String.
But why do you want as String^ *, instead yust String^
|
|
|
|
|
the C++/CLI function will be returning a value in the string passed in.
sort of like in c#
void GetName(ref string nameStr)
{
nameStr = "sam";
}
in c++ it would be
void GetName(string^ * nameStr)
{
*nameStr = "sam";
}
The problem happened when I tried to call c++ from c# since c# doesn't understand * unless it's unsafe.
|
|
|
|
|
As i coud see with docmetation, (Nothing at all) And my test, i coud see that it isn't possible to do as reference. Why don't you use as return. If you wan't a multiple variables, you coud use struct.
This coud be a bug, missing features or left out Intentionaly.
|
|
|
|
|
I figured it out. if you want to pass variables around as reference in C++/CLI you have to mark them with a %.
so instead of
void GetName(String ^ * name)
{
*name = "sam";
}
you do this:
void GetName(String^% name)
{
name = "Sam";
}
then you call it from c# like this:
String nameStr;
GetName(ref nameStr);
|
|
|
|
|
Thanks ByStorm. You saved my life. Been searching for this for weeks.
|
|
|
|
|
hi all,
i am writing a C programin Linux.
i want to make a system call and assign its result in to a variable.
how can i do this?
thanks in advance
|
|
|
|
|
i have found the answer myself and writing it down here;
popen() function did the work for me
Library: stdio.h
Prototype: FILE *popen(const char *command, const char *type);
Syntax: FILE *fp;
fp = popen( "ls -l", "r");
Notes:
command - is the command to be issued.
type - r - read O/P from command.
- w - Write data as I/P to command.
|
|
|
|
|
I'm glad you found your answer. If you have more questions, please ask in the right forum, this one is for managed C++ only.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
which forum could i ask that question? i havent seen a forum about C.
|
|
|
|
|
He means the "Visual C++ / MFC" forum, because it is a more general forum.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
There is no such thing as mananged C, AFAIK. Therefore, C questions end up in the visual C++ forum.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
hello to everybody.
i have a problem about polynomials by using c which includes a link command to mupad. but i am new at c++ and mupad programmes, and i cant find examples about the mixture of c and mupad.
1) the c programme must be able to take the degree and constants and sensitivity of the polynomial from user.
2) the programme must be able to find a root of the polynomial with a given initial value by using Newton-Raphson method.
3) the programme must be able to sense that is subjected to multiple root, and it must be able to prevent the negativities of this condition.
4) and the programme must do the steps 2 and 3 by using mupad.
if somebody can help me about this soon, i will be very grateful.
have a nice day to everybody...
|
|
|
|
|
What on earth is mupad ? Does it have something to do with the .NET framework, or are you in the wrong forum ? Either way, this smells like homework to me.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: What on earth is mupad ?
MuPad[^]...
A pretty cool tool, used it in a course once...As far as tying it into .NET, I am not too sure.
If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa
|
|
|
|