-
December 11th, 2013, 10:51 AM
#1
com+ dll and write to event viewer
i want to write to event viewer
Code:
oid EventLogCls::WriteError( char* msg) {
HANDLE hes = RegisterEventSource(0, appName);
if(hes) {
WORD dwEventType = EVENTLOG_ERROR_TYPE;
ReportEvent(hes, dwEventType, 0, 0, 0, 1, 0,(const char**)&msg , 0);
DeregisterEventSource(hes);
}
}
the error that i get is on the line of "ReportEvent"
error C2664: 'ReportEventW' : cannot convert parameter 8 from 'const char **' to 'LPCWSTR *'
what should be changed?
-
December 11th, 2013, 04:39 PM
#2
Re: com+ dll and write to event viewer
LPCWSTR is constant wide string. So you have to convert your msg to wide string and pass the latter to ReportEvent. Or explicitly specify ReportEventA.
Last edited by Igor Vartanov; December 11th, 2013 at 04:42 PM.
Best regards,
Igor
-
December 11th, 2013, 05:31 PM
#3
Re: com+ dll and write to event viewer
Are you compiling as ASCII or UNICODE? That parameter of reportevent() is typed as LPCTSTR* so if you are compiling as ASCII it should compile as LPCSTR * which is consistent with how you are trying to use it. As it thinks it should be a LPCWSTR* it looks like you are compiling as UNICODE. In which case, why are using char * as the argument for WriteError() and not LPCTSTR? which would make converting ascii to wide not required or don't need to explicity specify ReportEventA() as suggested by Igor in post #2.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 11th, 2013, 06:15 PM
#4
Re: com+ dll and write to event viewer
yes i compile as unicode. thanks both of you.
one more question :
when i try to debug i get error that
BSTR* message; //used to accept return value from server.
message is not initialized.
but when i am in release mode i don't get into this error.
what the correct way to init this type?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|