|
you can use #if macro and check whether debug, then load the debug icon else release icon.
|
|
|
|
|
Thanks for the info. What should I put in my code for the #if macro to check whether it is debug?
Thanks.
|
|
|
|
|
#ifdef _DEBUG
make use of the above #if macro and assign some variable value for debug version and for release version.
Before starting the application. Check the variable value and determine whether it is debug or release version.
Work hard and bit of luck is KEY to SUCCESS.
|
|
|
|
|
Hey there!
I'm writing a DLL as a plugin for an unmanaged piece of software, the DLL exports a struct with basic information such as name etc. There is no problem with this, it works well, other than a couple of compiler warnings that I wont go into just yet.
In my plugin, I want to use a managed class (__gc). I declare it as global like this:
<code>gcroot<COmg __gc*> Omg;</code>
Here is the class definition:
<code>public __gc class COmg
{
public:
COmg( void ) {}
~COmg( void ) {}
};</code>
This still compiles and loads fine, until I try and use my gcroot'ed class:
<code>Omg = new COmg;</code>
It dies at this line, as far as I know im linking with the .NET framework fine, because everything compiles and runs, and i've done similar projects to this in the past. I tried calling this in try/catch braces but it doesn't help.
I'd appreciate any help! Thanks.
P.S. Here are the compiler warnings that may be contributing to this?
<code>MSVCRT.lib(checkclr.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
MSVCRT.lib(secchk.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
Core.obj : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators</code>
|
|
|
|
|
I need my dialog boxes to have the behaviour that if it is open, you can't activate any other form until it is "closed" (usually by clicking 'OK', 'Cancel', or something similar); i.e., if I have opened an "Options" box from my main form, I can't click back in my main form until I either set all my options and click 'OK', or just click 'Cancel'... And if you do try to click back into the main form, it will make a beep...
For now, I just hide the main form, show the dialog, then when the user is done in the dialog, hide it and reshow the main form... Obviously, I don't really like doing it this way but can't figure out how to provide the functionality I described... Any help is greatly appreciated...
TIA
|
|
|
|
|
If you're using .NET, it's ShowDialog() instead of Show(), if it's MFC, it's DoModal() instead of whatever it is to show a modeless dialog box.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi everyone!
I’m trying to write a global hook in C# and C++\CLI. I’m almost done if there wasn’t this little delegate problem.
I get the function pointer to a delegate and pass it to my hook.dll. The delegate gets called for a few seconds but then the delegate seems to be relocated on the CLR heap.
If tried using a GCHandle but as far as I can tell this only prevents the garbage collector from collecting my delegate and doesn’t stop relocation.
Then there is pin_ptr. But a pinning pointer only works till it goes out of scope and it can only be declared locally so this happens immediately after I get the function pointer. By the way, I use ...
proc = (HOOKPROC)(Marshal::GetFunctionPointerForDelegate(innerEventHandler).ToPointer());
... to get the function pointer.
If anyone knows how to pin the delegate for as long as I need to point to it from unmanaged code or has any ideas, workarounds, etc. please let me know!
Thank you very much in advance!
Regards,
Florian
|
|
|
|
|
I don't know how your program runs. if your program is started by Application.Run, you should be able to pin the delegate BEFORE Application.Run and then cast it to a native global function pointer. if your program is started by MFC, you probably can not pin the delegate in CYourApp::Initinstance since, but you can pin it in your CWinApp::Run override and then cast it to a native global function pointer or a member varianble of CYourApp.
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
I wrote a little C# test app. Here's the relevant code snippet:
[STAThread]<br />
static void Main()<br />
{<br />
Form1 form = new Form1();<br />
TestDelegate test = new TestDelegate(form.Test);<br />
GCHandle handle = GCHandle.Alloc(test, GCHandleType.Pinned);<br />
Application.EnableVisualStyles();<br />
Application.Run(form);<br />
handle.Free();<br />
}
As soon as the debugger hits the line ...
GCHandle handle = GCHandle.Alloc(test, GCHandleType.Pinned);
... I get an ArgumentException:
Object contains non-primitive or non-blittable data.
In the MSDN it says:
An instance with nonprimitive (non-blittible) members cannot be pinned.
As I understand it, delegates can't be pinned by using GCHandle.Alloc().
|
|
|
|
|
delegate int BrowseCallBackProcDelegate(
unsigned/*HWND*/ hwnd, unsigned int/*UINT*/ uMsg
, unsigned/*LPARAM*/ lParam, unsigned/*LPARAM*/ lpData);
[STAThreadAttribute]
int main(array<system::string ^=""> ^args)
{
Form1^ pForm1=gcnew Form1();
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
BrowseCallBackProcDelegate^ BCBD =
gcnew BrowseCallBackProcDelegate(Form1::BrowseForFileCallBackProc);
pin_ptr<browsecallbackprocdelegate^> pBCBD= &BCBD;
IntPtr delegatePointer =
Marshal::GetFunctionPointerForDelegate(BCBD);
pForm1->m_pbi->lpfn=static_cast<bffcallback>(delegatePointer.ToPointer());
// Create the main window and run it
Application::Run();
return 0;
}
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
Thank you for trying but my application is written in C#.
Only the hook Dll is written in C++/CLI because it's simply not possible to write a global hook entirely in managed code.
|
|
|
|
|
Thanks to Tomas Restrepo the problem is solved.
He wrote:
Florian,
> thank you for your reply but I'm afraid it doesn't work. The Dll project
> compiles fine but as soon as I run my C# test app I get an
> ArgumentException ("Object contains non-primitive or non-blittable
> data."). Seems like GCHandle::Alloc() has a problem with my delegate ...
> Any suggestions?
Ahh, true, you are completely correct.
Thinking more closely to what you want to do, I realize you might not need
to actually pin the delegate at all; just keep a reference to it alive so
that it is not garbage collected (it actually does *not* matter that it
moves around in memory, as that won't affect the call to it from unmanaged
code in this particular case).
I looked around to verify this, and found what I was looking for:
http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx
Here, Chris Brumme explains in detail:
"Along the same lines, managed Delegates can be marshaled to unmanaged code,
where they are exposed as unmanaged function pointers. Calls on those
pointers will perform an unmanaged to managed transition; a change in
calling convention; entry into the correct AppDomain; and any necessary
argument marshaling. Clearly the unmanaged function pointer must refer to a
fixed address. It would be a disaster if the GC were relocating that! This
leads many applications to create a pinning handle for the delegate. This
is completely unnecessary. The unmanaged function pointer actually refers
to a native code stub that we dynamically generate to perform the transition
& marshaling. This stub exists in fixed memory outside of the GC heap.
However, the application is responsible for somehow extending the lifetime
of the delegate until no more calls will occur from unmanaged code. The
lifetime of the native code stub is directly related to the lifetime of the
delegate. Once the delegate is collected, subsequent calls via the
unmanaged function pointer will crash or otherwise corrupt the process. In
our recent release, we added a Customer Debug Probe which allows you to
cleanly detect this - all too common - bug in your code. If you haven't
started using Customer Debug Probes during development, please take a look!"
Hope this helps!
--
Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/
My response:
Hi Tomas!
> Hope this helps!
Problem solved! :-) Thank you!
It had nothing to do with the delegate at all. The problem was the return
value in my unmanaged callback. The hook worked till the app window lost
focus. After reactivating the window my delegate didn't receive any
keystroke messages. I assumed that this was because the delegte has been
relocated on the heap. Actually at this point it should have been clear that
I'm wrong. My application didn't crash which most likely would have happend
if my function pointer was pointing "somewhere" in the memory.
I have a few more problems now but I think I can figure them out on my own.
Thanks again!
Regards,
Florian
|
|
|
|
|
How can i stop program from loading if another instance of that program exist.
|
|
|
|
|
|
Search this site - or pretty much any code site - for the word singleton.
Cheers,
Tom Archer - Visual C++ MVP
Archer Consulting Group
"So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe
|
|
|
|
|
I am creating an aplication, that requires .NET Framework 1.1. I know how to check if framework is installed. I don't want to create a large instaler. My application only has about 120KB. I have use unmanaged command to detect if is installed. Then i have tried on another commputer with Windows 2000 without .NET Framework. And i got an error, that it wants to have mscorelib.dll. You can check a sample below to know what i think.
I hope you understand what i want to know.
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>
using namespace CDDvdOrganizer;
bool IsDotNetInstalled()
{
HKEY key;
bool bRunInstall = true;
if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\.NETFramework\\policy\\v1.1", 0, KEY_READ, &key))
{
bRunInstall = false;
BYTE val[10];
DWORD len = 10;
if (ERROR_SUCCESS == ::RegQueryValueEx(key, "4322", NULL, NULL, &val[0], &len))
{
char *pVal = (char *)&val[0];
if (0 == ::strcmp(pVal, "3706-4322"))
{
bRunInstall = true;
}
::RegCloseKey(key);
}
if (bRunInstall == false)
{
::MessageBox(NULL, "You must instal .NET Framework 1.1", "Error", MB_OK | MB_ICONERROR);
}
}
return bRunInstall;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
if (IsDotNetInstalled() == false)
{
PostQuitMessage(0);
}
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
Application::Run(new Form1());
return 0;
}
ps: Sorry for my poor english.
|
|
|
|
|
Saksida Bojan wrote:
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA; Application::Run(new Form1());
This is managed C++ code. You need to create an unmanaged project in order for it to not require the .NET framework. Your code is fine, these lines are not, and your project is therefore not either, it's a MC++ app.
I assume you know this, as you're asking the MC++ board. MC++, by definition, requires the .NET framework.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
So i must create Win32 or MFC Application detect, and if is installed run my app. I Know dis is MC++ forum, but how can i use to run other exe with some command line in Win32 syntax, Please.
ps: I Don't like programing in MFC and Win32.
|
|
|
|
|
Saksida Bojan wrote:
So i must create Win32 or MFC Application detect, and if is installed run my app
But of course. MC++ needs the exact same libraries as C#. How else did you think it worked ?
Saksida Bojan wrote:
but how can i use to run other exe with some command line in Win32 syntax, Please.
::ShellExecute.
Saksida Bojan wrote:
ps: I Don't like programing in MFC and Win32.
Sorry, but you're stuck with it for this. The funny thing is, you say that, but as far as I could see, nearly all your code WAS perfectly fine Win32, you were calling Win32 APIs for registry access, that's for sure.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks For the help. I didn't fully write this code. Someone posted on .NET Framework forum and i changed a bit.
|
|
|
|
|
|
Using SetEnvironmentVariable and other related API calls I am able to set only the "Environment Variables" specific to the process. How do I make these settings Global?
Thanks in Advance
|
|
|
|
|
Hi,
I want to monitor the file system operations done by the user,
namely
1. File/Folder Open,
2. File/Folder Copy,
3. File/Folder Rename,
4. File/Folder Delete,
5. File Save and
6. File/Folder Move operations.
I tried ICopyHook interface but it gave the information on folder Delete, Rename and Copy Operations alone.
It was not monitoring folder Open and Move operations. It also did not monitor any file based operations. Please suggest me the way to monitor the file/folder operations.
Thanks in Advance.
|
|
|
|
|
System::String *table;<br />
<br />
switch(table)<br />
{<br />
case 'CD':<br />
strTempSelectCommand = S"SELECT ID FROM CD WHERE ID=";<br />
break;<br />
case 'DVD':<br />
strTempSelectCommand = S"SELECT ID FROM DVD WHERE ID=";<br />
break;<br />
<br />
default:<br />
break;<br />
}
I got
c:\Projecti\CDDvdOrganizer\Core\CDDvdCore.h(155): error C2450: switch expression of type 'System::String __gc *' is illegal
Can anybody help me? Thanks in advance
|
|
|
|
|
you cannot use 'CD' , 'DVD' case statements.
single quotes are for single characters. if you want to use strings, it should be double quotes "" instead
but unfortunaltey, switch dont work with string. you must change it to an if - else if - else statement...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|