|
|
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
|
|
|
|
|
Well, I don't know about a C++ version, but this[^] is the Java version. Java is close cousin to C++, so it should do the job for you.
RageInTheMachine9532
|
|
|
|
|
When I compile my .exe the compiler give me this error:
"error LNK2020: unresolved token (0A0000FD) SysStringByteLen"
"error LNK2020: unresolved token (0A000101) SysAllocStringByteLen"
This problem occur when I set the proprety project "Treat wchar_t as Built-in Type" (in th C/C++\Language Menu) to "No". My project use Managed Extensions and C# class.
I try (how is described in MSDN) to include "oleauto.h" and to link oleaut32.lib, but it was all in vain.
Thank you very much for any answer.
|
|
|
|
|
Hi !
I am ran into a great problem I can not solve. I need to write a Dial-Up Server project in Win98 by visual c++.
I do followed steps:
1) With TAPI wrote a program that can wait fo call.
2) After client Dial-in (by Dial-up networking),my program answer and connect to client. But problem is here that I can't write the code that build the RADIUS packet for reply to packet that is sent from client.
If could help, please let me know.
A BIG thanks in advance.
|
|
|
|
|
How can I convert managed string (System::String) to unmanaged array of chars? (char *)
--------
Dave
|
|
|
|
|
<font color=green>
#include <vcclr.h>
String* s = S"Hello";
const __wchar_t __pin * str = PtrToStringChars(s);
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - Jörgen Sigvardsson
|
|
|
|
|
Hi,
I have a Object derived class (managed) which is called 'MyObject', and I want to perform the UNmanaged method 'PostThreadMessage(UINT threadMessage, WPARAM, LPARAM)' using a 'MyObject' object as WPARAM. like this:
MyObject *pObject = new MyObject;
myThread -> PostThreadMessage(WM_MYMSG, (WPARAM)pObject, NULL);
How can I convert it?
And how to convert back ?
Thanks in advance.
|
|
|
|
|
You'll need to pass gcroot<MyObject>* instead.
|
|
|
|
|
I am trying to wrap an extensive C++ library in managed code , but I am falling over at the first hurdle. I build a simple console app as below and the first time I run it it works. I then clean the project, close it , reopen it and rebuild it and I get "void __cdecl operator delete(void*) (??@YAXPAX@Z) already defined in LIBCMTD.lib (dbgdel.obj)" . I think I have to specify a managed or unmanaged new/delete for the managed or unmanaged objects , but I cannot see how. Anyone help ?
<br />
#include "stdafx.h"<br />
#include "afxwin.h"
#include "afxext.h"
#using "mscorlib.dll"<br />
<br />
using namespace System;<br />
<br />
#pragma unmanaged<br />
class UnManaged<br />
{<br />
public:<br />
<br />
UnManaged()<br />
{<br />
}<br />
~UnManaged()<br />
{<br />
}<br />
void Show()<br />
{<br />
AfxMessageBox("Hello From the UnManaged world");<br />
}<br />
<br />
};<br />
#pragma managed<br />
public __gc class MyManaged<br />
{<br />
public:<br />
MyManaged()<br />
{<br />
m_ptr = new UnManaged;<br />
}<br />
~MyManaged()<br />
{<br />
delete m_ptr;<br />
}<br />
void Show()<br />
{<br />
m_ptr->Show();<br />
}<br />
private:<br />
UnManaged *m_ptr;<br />
};<br />
int _tmain()<br />
{<br />
Console::WriteLine("Hello Managed World");<br />
MyManaged *mg = new MyManaged;<br />
mg->Show();<br />
return 0;<br />
}<br />
<br />
>
|
|
|
|
|
Everytime I have a few SqlDataAdapters + DataSets on my form, the designer takes
over 10+ minutes to just open up the form!
What the heck is wrong with it and how do I fix this? Anyone else have this problem?
Thanks
|
|
|
|
|
Hi,
I have a simple doubt.
I've created a struct TEST like this:
_value struct TEST
{
String *str;
int cont;
};
When I try to dynamically allocate TEST like this:
TEST *pTest = new TEST;
A compilation error says to me that 'a value type object cannot be dynamically allocated with managed members on C++ (nogc) heap'
I must use the 'str' variable within this structure, so how can I dynamically allocate TEST ?
Thanks in advance.
|
|
|
|