|
Hi All
i have defined a __value type class.How can i declare and create it in UnmanagedC++ class using new operator on the C runtime heap?
For example
public __value MyClasss
{
public:
int a;
}
//my unmanaged classs
class MyUnmanagedCPP
{
void SomeMethod()
{
MyClasss *pMyClass = new MyClasss();// here i'm getting error C3828
}
}
|
|
|
|
|
This is explained in depth in my book, Extending MFC Applications with the .NET Framework, but the main issue is that managed objects are dynamically allocated on the CLR heap (not the C++ free store). In your particular situation, you're probably getting C3828 because you're writing an MFC applications and running it in Debug mode where the new operator is being #define'd as a placement new operator. You need to do the following where 1) the new operator is being undefined and 2) __nogc is forcing a GC heap allocation instead of a C++ heap allocation:
void Cdeletethis3Dlg::OnBnClickedOk()
{
#pragma push_macro("new")
#undef new
MyClasss *pMyClass = __nogc new MyClasss();
#pragma pop_macro("new")
}
Cheers,
Tom Archer
* Inside C# -Second Edition
* Visual C++.NET Bible
* Extending MFC Applications with the .NET Framework
|
|
|
|
|
Hi everybody!
I am looking for a parser to read vCalendar and vCard streams.
Any Suggestions?
Thanks for help in advance!
|
|
|
|
|
I am having a trouble of getting image from the hard disk.
|
|
|
|
|
System::Drawing::Image.FromFile (static method)
The graveyards are filled with indispensible men.
|
|
|
|
|
If you are using managed C++ here is an article which may help you...
http://www.thecodeproject.com/managedcpp/mcppwinforms02.asp
|
|
|
|
|
He said under c. I assume that means Win32 API only and this is the wrong forum...
John
|
|
|
|
|
I am having trouble with a Forms application I'm writing. I have 3 forms: a main form, Form1, and two modal dialogs, Forms 2 and 3, that are called from the main form. The two dialogs are intended to change certain "control parameters" that are used by the main form to run a control algorithms. So I need the two dialogs to be able to set certain variables that are used by the rest of hte program. Also, when I open one of hte dialogs, the controls on that from should reflect the current state of those variables. I cannot figure out how to do this.
I thought I could declare global variables that could be accessed by all three forms. That way, when I open a dialog, its controls would be set based on the current values of those globals. Then, when I close the dialog and apply the changes, those changes would be saved back to the global variables. I tried this, and I can't seem to define variables that are accessible to all the dialogs.
Am I going about this all wrong? Can anyone help guide me in the right direction? ANy help would be greatly appreciated.
Andrew Krajnik
|
|
|
|
|
I cant remember if windows forms has the OnInitDialog(), if so override that and for the closing of the dialog you can override OnClose().
when you overwrite onclose make sure you call DestroyWindow() from the parent class.
|
|
|
|
|
Hello All,
I trying to call an unmanged code function from managed code and the unmanaged code function requires a type of WCHAR. How can I convert a __GC String to type of WCHAR so it be passed to the function. If I type out the value, such as const WCHAR *pdn = L"Some value"; It works; however I need the "Some value" to be passed in as a variable. By the way this unmanged code is in unicode, if that helps. Thanks, DC
|
|
|
|
|
|
Thanks,
When I try this I get the following:
cannot convert parameter 1 from 'const wchar_t __pin *volatile ' to 'WCHAR *' Conversion loses qualifiers: Here is the code
Unmanaged Code
UserStatus* WaitForChanges(WCHAR* dn)
{
UserStatus* status = new UserStatus();
MonitorLDAPChanges(pdn);
return status;
}
Managed Code
const __wchar_t __pin * str = PtrToStringChars(dn);
WaitForChanges(str);
|
|
|
|
|
I got it I forgot to put the 'const' in the method.
|
|
|
|
|
DR Clevenger wrote:
I got it I forgot to put the 'const' in the method
Yep
Here's the thing.
The __pin keyword is used to indicate that the value should not be moved in memory. This is done because a .NET String is subject to being moved about by the GC and when you convert that data into a WCHAR* for purposes of using that pointer over any length of time, you need to ensure that the data is not moved. The WCHAR* is also defined as const because String objects are immutable.
Anyway, you probably know this, but I wanted to give you a complete answer on what is going on here just in case.
Cheers,
Tom Archer
* Inside C# -Second Edition
* Visual C++.NET Bible
* Extending MFC Applications with the .NET Framework
|
|
|
|
|
Thanks for your help and the information.
|
|
|
|
|
If I have a bit of code like this:
String *s;
int x = 5; y = 10;
Now I want s = "x = (value of x), y = (value of y)"
How do you do that? I hope I explained correctly. I want to be able to change the value of x or y without changing more code.
|
|
|
|
|
int x = 5;
int y = 10;
String* s = String::Format(
S"x = {0}, y = {1}", __box(x), __box(y));
|
|
|
|
|
Hi everybody,
i'll try to explain my problem as short as possible:
->My C++ Dll (Native) should be able to call a C# DLL.
Therefore i implemented a managed C++ dll as a bridge( to
avoid COM).
So, the C++(nat) calls the c++(.net) dll, which calls the c# dll.
When the program is started on a local drive, everything
works perfectly, but once it is copied to a network drive
and run form there, loading the "bridge" - dll fails.
In detail : The C++ 6.0 dll uses LoadLibrary to load
the managed C++ dll and immedeately exits with Error 1114 "
Dll initialization failed" - but ONLY started from a network drive.
( calling other dll's works ). I already tried to make a static
link, same error... only on a network drive...
I don't even have to call a function for getting the error..
I'm trying to find the mistake for a long time... but i think
i'm at the end of my wisdom...
Has anybody some kind of an idea, why
calling my C++.Net dll only works on a local drive???
Problem with the dll- entry-point?
Looking forward to some help! Thanks in advance!
Michael
|
|
|
|
|
It's because of security restrictions, no doubt.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Hi!
But which restrictions? I do have w/r rights for that drv.
In addition, my .exe has already successfully called 1 other dll (which is native c++ (fortunately ) before calling the c++ managed dll.
Meanwhile, I used the MS Dependeny walker. The profile results
seem to show that there is a problem even when the program
is started from a local drive ( by the way: which u don't notice
without any tool, because it runs correctly )
Profile: ( static link this time )
caloader.exe = my exe
cabridge = my c++ managed.dll
Started "CALOADER.EXE" (process 0x6E8) at address 0x00400000.
Loaded "NTDLL.DLL" at address 0x77F40000.
.
.
.
Loaded "CABRIDGE.DLL" at address 0x10000000.
Loaded "MSCOREE.DLL" at address 0x79170000.
DllMain(0x78000000, DLL_PROCESS_ATTACH, 0x00000000) in "RPCRT4.DLL" called.
DllMain(0x78000000, DLL_PROCESS_ATTACH, 0x00000000)
.
.
.
Entrypoint reached. All implicit modules have been loaded.
DllMain(0x10000000, DLL_PROCESS_ATTACH, 0x0012FD30) in "CABRIDGE.DLL" called.
Loaded "MSCORWKS.DLL" at address 0x791B0000.
Loaded "MSVCR70.DLL" at address 0x7C000000.
Loaded "FUSION.DLL" at address 0x79040000.
.
.
.
Loaded "MSCORLIB.DLL" at address 0x79780000.
Loaded "MSCORLIB.DLL" at address 0x79960000.
DllMain(0x10000000, DLL_PROCESS_ATTACH, 0x0012FD30) in "CABRIDGE.DLL" returned 1 (0x1).
DllMain(0x77E40000, DLL_THREAD_ATTACH, 0x00000000) in "KERNEL32.DLL" called.
DllMain(0x77E40000, DLL_THREAD_ATTACH, 0x00000000) in "KERNEL32.DLL" returned 1 (0x1).
DllMain(0x77DA0000, DLL_THREAD_ATTACH, 0x00000000) in "ADVAPI32.DLL" called.
DllMain(0x77DA0000, DLL_THREAD_ATTACH, 0x00000000) in "ADVAPI32.DLL" returned 14679041 (0xDFFC01).
DllMain(0x78000000, DLL_THREAD_ATTACH, 0x00000000) in "RPCRT4.DLL" called.
.
.
First chance exception 0x80000003 (Breakpoint) occurred in "MSCOREE.DLL" at address 0x79172064.
First chance exception 0xC0000005 (Access Violation) occurred in "CABRIDGE.DLL" at address 0x10000005.
Second chance exception 0xC0000005 (Access Violation) occurred in "CABRIDGE.DLL" at address 0x10000005.
Exited "CALOADER.EXE" (process 0x6E8) with code 128 (0x80).
If you did read until here, thanks
here's my dll:
#include "stdafx.h"
#include "cabridge.h"
#include "windows.h"
extern "C"
{
#include <string.h>
}
#using "mycsharp.dll"
using namespace System;
using namespace mycsharp;
BOOL WINAPI DllMain (HMODULE hModule, DWORD x, LPVOID <)
{
return TRUE;
}
extern "C"
{
__declspec (dllexport) void __cdecl CallCobolAssistBridge(char *pszFileName, int icode, int hwndoutput)
{
String __gc *managed_input = new String(pszFileName);
mycsharp __gc *Mycsharp;
Mycsharp = new mycsharp;
Mycsharp ->DOStuff(managed_input,icode, hwndoutput);
return;
}
}
i hope this wasnt to much..
tanks,
byebye
|
|
|
|
|
sorry, please ignore
extern "C"
{
#include
}
was a copy / paste err
thanks for your help!
|
|
|
|
|
Hi, consider this thread as "solved" .
Meanwhile, someone has given me a hint :
The problems i seem to have are described
in the MSDN tecnical articles, topic "Mixed DLL Loading Problem".
It further seems to be some kind of runtime-problem and can be avoided somehow.. perhaps..
I'll try it out
|
|
|
|
|
good day,
just started with c++ coding...bfore i start on...wud require some help starting of with pacman....wud appreciate if i get help on the uml class diagram n the oop code...i'm starting on the turbo package..but wud go on with linux...appreciate yur help,
ozz
|
|
|
|
|
Ummm.... What?
PacMan? Turbo package? Linux?
Specifically, what are looking for help on?
...because your post made no sense whatsoever...
RageInTheMachine9532
|
|
|
|
|
sorry mate if i wznt clear.....simply need the oop code in c++ for pacman...thtz all
|
|
|
|