|
|
Hi. i'm trying to understand event logging. I got this sample function from MSDN on adding source into the registry. Is this code correct? It's hard to learn something when the sample is incorrect. Thanks
<br />
BOOL AddEventSource(<br />
LPTSTR pszLogName,
LPTSTR pszSrcName,
LPTSTR pszMsgDLL,
DWORD dwNum)
{<br />
HKEY hk; <br />
DWORD dwData, dwDisp; <br />
TCHAR szBuf[MAX_PATH]; <br />
<br />
<br />
wsprintf(szBuf, <br />
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",<br />
<br />
pszLogName, pszSrcName); <br />
<br />
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szBuf, <br />
0, NULL, REG_OPTION_NON_VOLATILE,<br />
KEY_WRITE, NULL, &hk, &dwDisp)) <br />
{<br />
printf("Could not create the registry key.");<br />
return FALSE;<br />
}<br />
<br />
<br />
if (RegSetValueEx(hk,
"EventMessageFile",
0,
REG_EXPAND_SZ,
(LPBYTE) pszMsgDLL,
(DWORD) lstrlen(pszMsgDLL)+1))
{<br />
printf("Could not set the event message file."); <br />
return FALSE;<br />
}<br />
<br />
<br />
dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | <br />
EVENTLOG_INFORMATION_TYPE; <br />
<br />
if (RegSetValueEx(hk,
"TypesSupported",
0,
REG_DWORD,
(LPBYTE) &dwData,
sizeof(DWORD)))
{<br />
printf("Could not set the supported types."); <br />
return FALSE;<br />
}<br />
<br />
<br />
if (RegSetValueEx(hk,
"CategoryMessageFile",
0,
REG_EXPAND_SZ,
(LPBYTE) pszMsgDLL,
(DWORD) lstrlen(pszMsgDLL)+1))
{<br />
printf("Could not set the category message file."); <br />
return FALSE;<br />
}<br />
<br />
if (RegSetValueEx(hk,
"CategoryCount",
0,
REG_DWORD,
(LPBYTE) &dwNum,
sizeof(DWORD)))
{<br />
printf("Could not set the category count."); <br />
return FALSE;<br />
}<br />
<br />
RegCloseKey(hk); <br />
return TRUE;<br />
}<br />
From : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/adding_a_source_to_the_registry.asp
|
|
|
|
|
Hi,
In my MDI Application I use CScrollView. I need to get the full view size when the view is not in maximized.
Thanks in advance!
Have A Nice Day!
Murali.M
|
|
|
|
|
I want to save a window as a bitmap file.First I show a dialog in order to get the file name by using function domodal(),then I convert the window to a DIB and save it as a bitmap file. All is OK but the dialog is also be showed in the image!
What wrong?
I thought the dialog should not be diaplayed in the wonodw yet after the function domodal().
I have add funtion Invalidate() after the domodal(), but no change.
andy
|
|
|
|
|
You're plainly grabbing the screen while the dialog box is up - where else could it come from ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
But When will the dialog box disappear?
andy
|
|
|
|
|
Hi all !
I am buill dll application in VC++ with MFC AppWizard(dll).
In the file StdAfx.h, I have included the line follows into it's header.
#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
no_namespace \
rename( "EOF", "adoEOF" )
I using msado15.dll for accessing the .mdb database. But When I builded my application, I always met some mistake . Example
'LockTypeEnum' : 'enum' type redefinition
I really don't known why ? I done well in the normal application but in dll application I can't...
pls, help me resolve the problem. Thanks alots
|
|
|
|
|
Can you try this:
#import <msado15.dll> rename_namespace("ADO") rename("EOF","ADOEOF")
|
|
|
|
|
I haved try. It done well. Thanks alots
|
|
|
|
|
Hi everybody : ). Before I begin, I must say I'm a newcommer to the world of Visual C++. Up until a few days ago I didn't know much about it, but I'm a fast learner, specially when I really have to do do something. And I really have a complex task that I need to accomplish. It's related to the SysTray. I won't get into that... anyway, the toughest part is this: creating a hook on Explorer.exe to monitor the messages it sends to the Systray's window.
What I need to make is a DLL to call from my VB application. I know how to do all that but here comes the problem. I have this VC++ DLL tutorial for a system-wide keyboard hook and I wanted to adapt this to VB.... Unfortunately, I didn't even get to adapting. Why? Because I got some compilation error that I am unable to correct. Here is the full source code of the module in cause (it's the header file of the DLL)
<br />
#define MAINHOOK_API _ _declspec(ddlexport)<br />
<br />
#define CCONV _stdcall<br />
#define NOMANGLE<br />
<br />
#define WH_KEYBOARD 2<br />
#define HC_ACTION 0<br />
<br />
typedef struct tagKBDLLHOOKSTRUCT {<br />
DWORD vkCode;<br />
DWORD scanCode;<br />
DWORD flags;<br />
DWORD time;<br />
DWORD dwExtraInfo;<br />
} KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;<br />
<br />
LRESULT CALLBACK KeyboardFunc (int nCode, WPARAM wParam, LPARAM lParam );<br />
<br />
#ifdef _ _cplusplus<br />
extern "C" {<br />
#endif<br />
MAINHOOK_API int InstallFilterDLL(void);<br />
MAINHOOK_API int UnInstallFilterDLL(void);<br />
#ifdef _ _cplusplus<br />
}<br />
#endif<br />
<br />
Of course you already saw probably what is the problem. Yeah, I know. Those "_ _cplusplus" tags. I don't know what they mean but my VC++6 doesn't seem to "know" them. In the book from where I took this code there wasn't any mention about "what kind" of C++ is this. The basic is that it doesn't compile. Here are the errors:
warning C4067: unexpected tokens following preprocessor directive - expected a newline
error C2485: 'ddlexport' : unrecognized extended attribute
error C2144: syntax error : missing ';' before type 'int'
error C2501: '_' : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found"
So? Anybody has any idea what I'm up against? : ). Thanks a lot for all the time you guys spend helping people such as myself : ). If I *EVER* get good enough, I promise I'll return the favor. And I'm a man of my word. But for now, I really need help with this...
P.S. It's for a good cause... I`m developing a freeware Application that most of you will probably like... if it's ever gonna be completed.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Is it my imagination or am I seeing a space between the two underscores?
Remove the space, and use two leading underscores and try again.
__cplusplus
not
_ _cplusplus
|
|
|
|
|
Nope, not your imagination... : ). But this is not the problem I think. This only solved one of the warnings of the compiler. I already did try that. I documented enough to know that __cplusplus is a known directive, but anyway, _ _cplusplus was in that book so.... Now that I put two leading underscores and compiled again I "only" get these errors:
error C2485: 'ddlexport' : unrecognized extended attribute
error C2144: syntax error : missing ';' before type 'int'
error C2501: '_' : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found
Also, what I did now is replace #define MAINHOOK_API _ _declspec(ddlexport) with #define MAINHOOK_API __declspec(ddlexport) (I put two leading underscores again.)
This resulted in this error
D:\Lucru\!!Aoleo\Exp\Exp.cpp(33) : error C2485: 'ddlexport' : unrecognized extended attribute beeing repetead 7 times in my CPP file. Here is my CPP file in case you were wondering... (I posted now the full source code, the header file is in my previous post).
By the way, this is a SIMPLE WIN32 DLL (not a DLL that exports some symbols or empty DLL, so you imagine how stdafx.h and stdafx.cpp look like).
<br />
<br />
<br />
#include "stdafx.h"<br />
#include "Exp.h"<br />
#include "WINUSER.H"<br />
<br />
HANDLE hInstance;<br />
HHOOK hhookHooks;<br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
DWORD ul_reason_for_call, <br />
LPVOID lpReserved<br />
)<br />
{<br />
hInstance = hModule;<br />
switch (ul_reason_for_call)<br />
{<br />
case DLL_PROCESS_ATTACH:<br />
case DLL_THREAD_ATTACH:<br />
case DLL_THREAD_DETACH:<br />
case DLL_PROCESS_DETACH:<br />
break;<br />
}<br />
<br />
return TRUE;<br />
}<br />
<br />
MAINHOOK_API int InstallFilterDLL(void);<br />
MAINHOOK_API int UnInstallFilterDLL(void);<br />
LRESULT CALLBACK KeyboardFunc (int nCode, WPARAM wParam, LPARAM lParam);<br />
<br />
MAINHOOK_API int InstallFilterDLL(void)<br />
{<br />
hhookHooks = SetWindowsHookEx(WH_KEYBOARD, <br />
(HOOKPROC) KeyboardFunc,<br />
(HINSTANCE) hInstance,<br />
0);<br />
return 1;<br />
}<br />
<br />
MAINHOOK_API int UnInstallFilterDLL(void)<br />
{<br />
int iResult;<br />
iResult = UnhookWindowsHookEx(hhookHooks);<br />
if (iResult == 0) return 0; else return 1;<br />
}<br />
<br />
LRESULT CALLBACK KeyboardFunc (int nCode, WPARAM wParam, LPARAM lParam)<br />
{<br />
return CallNextHookEx(hhookHooks, nCode, wParam, lParam);<br />
}<br />
What do you say about this? Either that book is not good, either I'm too much of a beginner to handle this. I worked with C# in the past year and half but this is a totally different game : )
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Whoops. Got it! I fixed it : ). Indeed I had to put two leading underscores before the "cplusplus" and also before "declspec". And then the mistake was that "DDL". It was a spelling mistake... I wrote DDL instead of DLL : ). Haha... well... anybody makes mistakes right? (what a pathetic excuse...).
Thanks Blake : )... I got this DLL working, but I do have some other problem with another one I made. Because this wasn't working I tried making it in another way by myself, as I learned this past couple of days... read the post above if you can help.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
|
Heyyyyyyy Alok : ). You noticed me? : ). I saw your comments a few times around here. How'r'ya doing? You didn't say anything on Yahoo messanger in the past time : ).
|
|
|
|
|
So, You think i Forget you, No Baby NO! .
Anonymous wrote:
You didn't say anything on Yahoo messanger in the past time .
as usual my yahoo Messeneger is Blocked,now Again i have to find new way to hack company Firewall
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Well, shoot an e-mail on theaxonn at yahoo dot com ! ::- ).
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
|
I haven't got any e-mail from you in a long time. Try sendin' something at "theaxonn at yahoo dot com".
The project is going strong... I need to do some stuff in Visual C++ and it's a bit hard, I never worked with it before but I began to get the hang of it ::- )
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
How do i add a custom menu(command) in the Tools menubar of MS Word? Help please, i'm a beginner!!
Also anyone knows how to disable the spell checker, progmatically??
|
|
|
|
|
|
I am attempting to use GetOpenFileName from a service on W2K and WXP. The service is set to interact with the desktop. The problem is that when the open dialog appears and the user selects the "Desktop" icon on the left panel of the open file dialog, it complains about "C:\Documents and Settings\LocalSystem\desktop" not existing. Note the "LocalDesktop" in that string. I want it to be the name of the current user.
So, how do I tell GetOpenFileName to use the currently logged-on user's context when using the open file dialog? Do I need to impersonate the logged-on user before calling GetOpenFileName? If so, how do I do impersonation WITHOUT asking for user credentials?
Some rudimentary example will suffice, you don't have to right the whole she-bang.
thanks you in advance.
ahz
|
|
|
|
|
In the article http://www.codeproject.com/system/newbiespawn.asp[^] the following code is given as a solution for launching a process and waiting for it to finish.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\MyProgram.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
The problem I found with this code is that ShellExecuteEx, in some cirsumstances, may not create a different process. For example, if in the lpFile you specify a URL and there is one instance of IE already running, this existing instance will be used. The documentation says that, in this case, ShellExecuteEx will return NULL in the hProcess. I found that this is not true. It returns a handle for the existing process. The problems is that the process is "signaled" already. Therefore, WaitForSingleObject does not block waiting for the process to finish and returns immediately.
The only difference between my code and the above is that in mine, I've added the flag SEE_MASK_FLAG_DDEWAIT to the fMask so the DDE exchange is guaranteed to be finished before ShellExecuteEx return.
Does anybody know how to solve this problem?
Lula Capixaba
|
|
|
|
|
You might try using CreateProcess instead. The drawback of CreateProcess is that you can't just pass it a URL. The benefit is that if the process didn't exist/create you don't get a process handle.
The benefit/drawback of ShellExecuteEx is that it acts more like the user typed the command.
Another drawback is that it must be called from an STA thread. (Or a thread that didn't call CoInitialize[Ex]).
|
|
|
|
|
Thanks ahz, but let me try to explain why I have to use ShellExecuteEx:
My application displays a list of files located in a repository (in another machine). If the user selects one of the files for viewing/editing, I make a copy of the remote file in the local disk and launch a viewer/editor for the file. This file can be of any type: a .doc, .gif, .txt, .html, .cpp, .h etc. I want to launch the application that is associated with the file extension... that's why I am using ShellExecuteEx. I used to launch it using CreateProcess after manually finding the application associated with the extension in the registry. The problem became complicated when I realized that on Windowx XP, the default viewer for .gif files is the "Windows Picture and Fax Viewer". It is in a DLL called shimgvw.dll and can be launched using a command like this:
rundll32.exe c:\windows\system\shimgvw.dll,ImageView_Fullscreen C:\temp\logo.gif
The problem here is that I don't know how to get the information to launch this viewer from the registry. Presumably, there are other applications like this, that are run from a dll and, therefore, I would need to know which function in the dll to call.
That's why ShellExecuteEx is easier. I don't need to know the exact command to launch the viewer/editor. It's done behind the scenes by Windows.
So I think there two solutions for my problem:
1) Make ShellExecuteEx work and return a valid process handle even when it does not launch another instance of the application (which is the case for the "Windows Picture and Fax Viewer"). In addition, this handle must not be in a signaled state as it does now.
2) Find a way to get all the information needed to launch any viewer/editor using CreateProcess. In the case of the "Windows Picture and Fax Viewer", for example, how do I get the "ImageView_Fullscreen" function info?
Any thoughts?
Lula Capixaba
|
|
|
|
|