|
Hi all, this is my first post. Normally I am able to figure out the problems I encounter either by searching this board or others like it on the web but not this time. I've been fighting with this for weeks now and am finally turning to you guys. Any and all help is appreciated.
I've got a CORBA Event channel feeding multiple applications data. If you are unfamiliar with CORBA it's okay, you don't need to know much aside from that the code generated for CORBA related functions in UNMANAGED. The data is pushed at a 1Hz interval and the applications register as a consumer to receive the data. My task is to create a common DLL for all Managed applications that are being built going forward that makes the registering and consumption of data easy and localized.
I've had little problem getting this to work with primitive data types but the final piece of my puzzle is to receive a sequence of data that is in a CORBA defined structure.
Here is what I am dealing: a Managed C++ DLL (built with CLR support) that contains Managed and Unmanaged(CORBA) classes, and a C# Application that references the DLL.
The MDA (Managed Debugging Assistant) Gives this description:An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
Attempting to call into managed code without transitioning out first. Do not attempt to run managed code inside low-level native extensibility points, such as the vectored exception handler, since doing so can cause corruption and data loss.
After hitting continue I get an ExecutionEngineException:
An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
**The following code snippets are in the Managed C++ DLL**
ManagedWrapper.h
public delegate void BasicCallbackDelegate(short cmd);
public delegate void NonBasicCallbackDelegate(array<EPClass^>^ epList);
[StructLayoutAttribute(Sequential, CharSet = Ansi )]
public ref struct ManagedBasicDelegateWrapper
{
[MarshalAsAttribute(UnmanagedType::FunctionPtr)]
BasicCallbackDelegate^ _Delegate;
};
[StructLayoutAttribute(Sequential, CharSet = Ansi )]
public ref struct ManagedNonBasicDelegateWrapper
{
[MarshalAsAttribute(UnmanagedType::FunctionPtr)]
NonBasicCallbackDelegate^ _nDelegate;
};
public ref class ManagedWrapperClass
{
public:
ManagedWrapperClass(ManagedBasiceDelegateWrapper^ cbd);
ManagedWrapperClass(ManagedNonBasicDelegateWrapper^ cbd);
};
ManagedWrapper.cpp
extern class BasicPushConsumer *BasicPushConsumerObject;
extern class NonBasicPushConsumer *NonBasicPushConsumerObject;
ManagedWrapperClass::ManagedWrapperClass(ManagedBasicDelegateWrapper^ cbd)
{
gt_Callback callback;
Marshal::StructureToPtr(cbd, safe_cast<System::IntPtr>(&callback), false);
BasicPushConsumerObject->SetCallbackInUnmanaged(callback);
}
ManagedWrapperClass::ManagedWrapperClass(ManagedNonBasicDelegateWrapper^ cbd)
{
ep_Callback callback;
Marshal::StructureToPtr(cbd, safe_cast<System::IntPtr>(&callback), false);
NonBasicPushConsumer->SetCallbackInUnmanaged(callback);
}
*pruned* NonBasicPushConsumer.cpp
typedef void (*gt_Callback) (short cmd);
typedef void (*ep_Callback) (array<EPClass^>^ epList);
void NonBasicPushConsumer::SetCallbackInUnmanaged(ep_Callback ptr2f)
{
scallback = ptr2f;
}
void NonBasicPushConsumer::ManagedMethodToCall(array<EPClass^>^ epList)
{
scallback(epList);
}
**The following code is part of the C# Application**
*pruned* Form1.cs
ManagedNonBasicDelegateWrapper mcf = new ManagedNonBasicDelegateWrapper();
mcf._epDelegate = new EntityPositionCallbackDelegate(CallbackFunction);
ManagedWrapperClass mwc = new ManagedWrapperClass(mcf);
public static void CallbackFunction(System.Array epList)
{
Console.WriteLine("CALLBACK!");
}
modified on Wednesday, November 4, 2009 6:44 PM
|
|
|
|
|
'System.Array' is pretty useless - more often used for COM interop - try changing the C# declaration to use a 'proper' C# array:
public static void CallbackFunction(EPList[] epList)
David Anton
http://www.tangiblesoftwaresolutions.com
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB
|
|
|
|
|
Unfortunately this did not remedy the issue, I have the same error. Anyone have any other suggestions?
|
|
|
|
|
Hi Expert,
I want to run command from my application and get the returned result.
ex: in the cmd i put "set MyVariableName" the string return is value of the Environment Variable.
I want to do it from my code and i want the returned value.
Is it possible or not and How?
Thanks.
|
|
|
|
|
Hi,
Am deleoping application using VC++ on VS2005. My application needs to switch to console application if the commandline parameters are mentioned on the command prompt console else to windows form dialog. for eg:
test.exe --help
on command prompt should display on command console(black backgrnd console window) and if cmd is
test.exe
window form should be opened.
This has been accomplished by creating the project of the type window form and then project properties->system->subsystem to Console (/SUBSYSTEM:CONSOLE)
But now the issue what i am facing are
1> when window form is opened with ex cmd test.exe, black color console window is also opened.
2> when console is closed, window form also closes
solutions i need correspondingly are
1> how to hide/close the console window when windows form is open?
2> can the Can console and window form controls be made independent? if yes how?
Searched and tried lots of solutions provided over net, but of less help.
Help on this will be appreciated.
Thanks,
Santosh
|
|
|
|
|
There is no way to hide the console programically.
A dirty way to achieve what you need is: Create two executables. First executable will be console and second will be windows. Second executable is your applications executable. Always invoke the first executable and if its is invoked using command line parameters, write the necessary details to the console. If no command line parameters are specified, start your main exe and exit this one.
Let me know if you find a better approach.
Best wishes,
Navaneeth
|
|
|
|
|
Agree but I need to deliver a single exe.
|
|
|
|
|
[DllImport("Kernel32.dll")]
extern int AllocConsole();
[DllImport("Kernel32.dll")]
extern int FreeConsole();
[DllImport("Kernel32.dll")]
extern int AttachConsole(UInt32 dwProcessId);
...
AllocConsole();
Console::WriteLine("Write to the console!");
...
FreeConsole();
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Great. Good to learn new things every day.
Best wishes,
Navaneeth
|
|
|
|
|
Hi,
My VC++ application(managed code) uses unmanaged code library(.lib) and am using VS2005.
During deployment, I also need to send few more dlls along with the exe. I just want all the modules (external dlls to be deployed and the exe) into a single exe.
I tried using ILMerge, but when i run the merged exe it throws up exception as "bad unmanaged code entrypoint". But if i try the same with pure managed code(without any unmanaged lib included), then the merged exe runs fine.
I also tried Netz. Could not successfully run with this too. Pure managed code runs fine here too.
So, clarification i need is whether the exe generated from a code(which has both managed and unmanaged code) can be merged with dlls? if yes, pls let me know the steps too.
Thanks in advance
-Santosh
|
|
|
|
|
Can't you statically link those libraries rather than providing DLL's?
Best wishes,
Navaneeth
|
|
|
|
|
Those DLL's are microsoft provided. I just want to avoid deploying msvc**.dll files.
Am amateur in application programming. So want to know Can DLL's be statically linked? if so how?
|
|
|
|
|
IL merge can work only with managed assemblies. I guess mixed mode and native DLLs are not supported. IMO, you don't have to deploy msvc runtime files manually. Get the redistributable package from MSDN and install it on target machine before your application is installed. That should install all the necessary dependencies.
Best wishes,
Navaneeth
|
|
|
|
|
Agree with your suggestion but my application will be used by the production line zombies. So, asking them to get the redistributable installed is a huge task for them.
Hence packaging everything into one is the solution i see. pls let me know how to do this.
Thanks
|
|
|
|
|
Hey guys. Maybe thats stupid question, but i am pretty curious why
i cannot inject a thread from application written in managed c++ .NET into for example
notepad.exe.
The code i am trying to inject is not .net - it is win32 code. NET in this example
used only for GUI - simple window with button "Inject", the rest of code is win32 only.
Actually the rest of the code is simply copied from console C application.
I am curious because, for example, i can inject a working thread from win32 application into native application(for example, from my_proggie.exe - which is win32 app, into smss.exe - which is pure native) if i am injecting native functions (for example, not OpenProcess but NtOpenProcess), why i cannot do the same thing here? And by the way, is it possible at all? I know it is possible to inject a dll loading routine even from C# app into C app, but how about a thread?
|
|
|
|
|
csrss wrote: i can inject a working thread from win32 application into native application(for example, from my_proggie.exe - which is win32 app, into smss.exe - which is pure native
I thought Win32 applications are also called as native. What do you meant by pure native? Also what is thread injection and what are you trying to achieve by that?
Best wishes,
Navaneeth
|
|
|
|
|
What am i trying to achive... for example i want some remote process to do something for me and i dont want to do it from my process, or i just need to get into remote process, or i am doing it just for fun. There are many reasons i might need to use it.
Win32 apps are win32 subsystem specific apps and they are not native, well you can call them native but thay are higher level then, for example, csrss (client-server runtime subsystem) app, or smss(session manager subsystem), you cannot run them inside win32 subsystem. for example disk check util. is native too - it runs before win32 subsystem initialization. For example CreateFile is win32 API, while NtCreateFile/ZwCreateFile is native API. And you know that ZwCreateFile you can call from win32 app, native app and kernel mode driver. But if you will try to inject some thread into, for ex. csrss, lets say thread has one function - ExitProcess, it will not work, but if NtTerminateProcess((HANDLE)-1, 0) will be injected - you will have a BSOD, because you forced csrss to shutdown itself.
Thats what i am talking about - just playing with system internals.
So i tried to do some injection stuff from managed c++ .NET and it is not working, and i dont know why. Maybe thats all about this .NET platform, code translating is some kind different. Well, what is funny it cannot even inject into itself - probably i have to do some debugging to get idea why is that so. Or i am missing something with function pointers and addresses? Thats whay i have posted my question here in hope to get some detailed info how these things works in case of managed c++
|
|
|
|
|
Hi All
I am using mysql,::_RecordsetPtr pRecordset and ODBC.I create database through code
<preprecordset=m_pconn->execute(_bstr_t("create database="" clientname"),0,="" adcmdtext);="">
It's work fine but i want to use refresh after creating database.There is any way to refresh mysql database through code.Plz help me
|
|
|
|
|
What do you mean by refresh database? And why are you using ODBC to connect MySQL from Managed code? A better alternative would be the connector provided by MySQL.
Best wishes,
Navaneeth
|
|
|
|
|
>(resources->GetObject(L"Ythree.Image")));
I need some help. The above code gets an image from .resX file.
What is the code if i want to load an image from the app.rc file?
I am finding that using resX, if i am using the same image more than once a new copy of the image is being created on executing the application and the code modified to point to images created when the program is executed.
Thanks for the time.
|
|
|
|
|
i think i have to use the imageList control for this as resX is the .net way of doing things.
|
|
|
|
|
if images are imported/used in resX using imagelist.
how do i store audio clips in the application resources? do i use app.rc for that?
also i would like to embed icons in it also. how and where do i store them?
thanks.
|
|
|
|
|
ok i think i have figured out how resX works.
thanks.
|
|
|
|
|
Yup, I did Google but nothing helped. I get strange linker errors.
Error 1 error LNK2001: unresolved external symbol "extern "C" int __cdecl wsprintfW(wchar_t *,wchar_t const *,...)" (?wsprintfW@@$$J0YAHPA_WPB_WZZ) ComPort.obj Lab1
Error 2 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegQueryValueExW(struct HKEY__ *,wchar_t const *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)" (?RegQueryValueExW@@$$J224YGJPAUHKEY__@@PB_WPAK2PAE2@Z) Lab1.obj Lab1
Error 3 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegQueryInfoKeyW(struct HKEY__ *,wchar_t *,unsigned long *,unsigned long *,unsigned long *,unsigned long *,unsigned long *,unsigned long *,unsigned long *,unsigned long *,unsigned long *,struct _FILETIME *)" (?RegQueryInfoKeyW@@$$J248YGJPAUHKEY__@@PA_WPAK22222222PAU_FILETIME@@@Z) Lab1.obj Lab1
Error 4 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegEnumValueW(struct HKEY__ *,unsigned long,wchar_t *,unsigned long *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)" (?RegEnumValueW@@$$J232YGJPAUHKEY__@@KPA_WPAK22PAE2@Z) Lab1.obj Lab1
Error 5 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegOpenKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,unsigned long,struct HKEY__ * *)" (?RegOpenKeyExW@@$$J220YGJPAUHKEY__@@PB_WKKPAPAU1@@Z) Lab1.obj Lab1
Error 6 fatal error LNK1120: 5 unresolved externals Lab1
The linker throws errors only in a Release configuration. In a Debug conf the project compiles successfully.
If I comment out lines where I use the functions above, the code compiles. But certainly is not what I want.
What's interesting, I use other functions from WinAPI and they work. Also wscanf_s compiles with no errors.
Also, wiping .obj files out (and all other which are generated during compilation) does not help
Thanks in advance --
Greetings - Jacek
|
|
|
|
|