|
sometimes you are right too, and this seems to be one of them.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
includeh10 wrote: in first test, app crashed and no idea to try-catch it.
You tried to write to an address which was not allocated as writable memory to your application.
The operating system detects that and issues a system exception for the application.
includeh10 wrote: in second test, GetName() is called properly without any problem (funny).
You are calling a method via static binding. Static binding in the code of your application is normal for your application.
The method itself is in the code space. Thus legal as well.
The method doesn't address any illegal addresses so no problem.
> how to detect, catch or provent crash from invalid pointers as tests above, or other common cases?
Find or buy libraries which detect memory problems, of many types.
Build your application with those.
Then run your application testing ALL of the code paths (there are other tools that track that.)
The library will tell you about improper memory usage.
|
|
|
|
|
|
Hi
I have a problem with an MFC Project that opens an email template, and sets some user properties on the mail item. The code I have been given with is as follows:
SetProperties()
{
LPDISPATCH userProps;
outlookmailitem->InvokeHelper(0xf816, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&userProps, NULL);
COleDispatchDriver* outlookUser = new COleDispatchDriver(userProps);
LPDISPATCH userProp1;
static BYTE params[] = VTS_BSTR VTS_I4 VTS_VARIANT VTS_VARIANT;
CString propertyName = _T("Email Marking");
outlookUser->InvokeHelper(0x66, DISPATCH_METHOD, VT_DISPATCH, (void*)&userProp1, params, propertyName, 1); //falls here!
COleDispatchDriver* outlookUserProp = new COleDispatchDriver(userProp1);
static BYTE params2[] = VTS_VARIANT;
VARIANT va1;
va1.vt = VT_BSTR;
va1.bstrVal = emailMarking.AllocSysString();
outlookUserProp->InvokeHelper(0x0, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, params2, &va1);
delete(outlookUserProp);
Where I have added "//falls here!" is where it fails, and I think this is parameter issue, again. I cannot tell you what the error message I am getting because all that VS2010 is giving me is unhandled exception.
Looking at MSDN for VBA - http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.userproperties.add.aspx#Y19 - it is final two parameters to me that Outlook is expecting, add to folders and display format. What I am trying to achieve is to ensure that the add to folder is set to false, and for the final one, I would like to set this to text if possible. How can set theses in MFC? What is the correct syntax? Do they need to set in this way or could Outlook set theses with the parameters being passed?
Thanks
|
|
|
|
|
Member 2972992 wrote: CString propertyName = _T("Email
Marking"); outlookUser->InvokeHelper(0x66, DISPATCH_METHOD, VT_DISPATCH,
(void*)&userProp1, params, propertyName, 1); //falls here!
Using a CString object is probably what is causing you grief.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
No, I think - tatic BYTE params[] = VTS_BSTR VTS_I4 VTS_VARIANT VTS_VARIANT; is correct because I have seen this in http://repositorium.googlecode.com/svn/trunk/AbstractSpoon/OutlookImpExp/Source/msoutl.cpp
What should CString be?
|
|
|
|
|
Member 2972992 wrote: What should CString be?
Without actually trying it, I honestly do not know. I'd try VARIANT and BSTR to see what they produce.
Since InvokeHelper() throws an exception, why are you not catching it and examining the actual cause?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
I would hazard a guess from the code that its the same issue you had before, regarding the passing of [in, optional] VARIANT parameters. Everytime you come across an [in, optional] VARIANT parameter, what you have to pass is the address of a VARAIANT that contains type VT_ERROR, and value DISP_E_PARAMNOTFOUND. In this case, from the static BYTE params[] declaration there are two "optional" parameters.
COleVariant varOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
LPDISPATCH userProp1;
static BYTE params[] = VTS_BSTR VTS_I4 VTS_VARIANT VTS_VARIANT;
CString propertyName = _T("Email Marking");
outlookUser->InvokeHelper(0x66, DISPATCH_METHOD, VT_DISPATCH, (void*)&userProp1, params, (LPCTSTR)propertyName, 1, &varOptional, &varOptional);
Notes:
I have not looked up what dispatch method 0x66 is so I am not 100% sure.
The presence of a VTS_VARIANT in the params array does not always mean optional, however an optional parameter is always a variant.
The VTS_BSTR in the params array of an InvokeHelper call is expected to be an LPCTSTR. to allow the CString to pass the correct value always type cast it to (LPCTSTR). The type casting is neccessary because InvokeHelper is declared as void AFX_CDECL InvokeHelper(DISPID dwDispID, WORD wFlags, VARTYPE vtRet, void* pvRet, const BYTE* pbParamInfo, ...); so the compiler doesnt know specifically what to pass. By type casting it you ensure the correct value is passed.
|
|
|
|
|
Hi
I have tried your suggestion and that did work! However, because one of parameters is a bool what is the correct syntax for passing a bool? Would it be COleVariantBool varOptionalBool (VT_TRUE, VT_ERROR); ?
Further, when the line for saving the properties is called InvokeHelper(0xf048, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
It gives an unhandled exception again. Looking at the MS Office VBA for this, properties don't save method, and it appears to me that when you add and set the properties this carries out the saving. Have I got this wrong? Is there something else I need to do?
Thanks
|
|
|
|
|
To pass a bool use one of these
COleVariant varTRUE((short)-1,VT_BOOL);
COleVariant varFALSE((short)0,VT_BOOL);
I am unsure why Save (0xf048) would cause an exception. What is the exception ?
I am also unsure why you dont use type-safe methods of invoking Outlook. Open the Class Wizard dialog "key combination Ctrl+W". Click "Add Class...". Click "From a type library...". Locate your MSOUTLxx.OLB, mine is in "C:\Program Files\Microsoft Office\Office12" click Open. Select the appropriate classes, or all of them, and click OK. This will add to your project header and implementation files that, in my humble opinion, will make your life easier.
|
|
|
|
|
I have learn C/C++ language already,and i want to read some famous books.
Is there any famous book to exsplain C/C++ programming?
Give me some advice.thanks~
|
|
|
|
|
|
I will go and have a look,thanks
|
|
|
|
|
Read several, they may have different approaches that will help you have a rounder understanding.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
The task manager shows the amount of physical memory:
Total
Cache
Available
Free
I would like to know how to get and/or calculate the amount of free memory, since this is not the same as reported by GlobalMemoryStatus(Ex).
Regards
|
|
|
|
|
See here. You'll need to change the values for object, instance, and counter.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
OK. Thanks. So far so good, but the function PdhAddCounter needs localized strings, thus in Germany you need german strings, in france you need french strings, etc. Damn, I'm not that language professional and the recently added function PdhAddEnglishCounter is not available on XP systems... ( I love those guys in Redmond...).
Is there a way to find out the localized corresponding language strings?
|
|
|
|
|
If you know the index equivalent of the string you are interested in, a call to PdhLookupPerfNameByIndex() would help. See here and here for more.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Thank you for this! AddEnglish..., what a joke!
Live's getting easier each day!
|
|
|
|
|
MSDN offers this[^].
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks, but I already know about that:
...since this is not the same as reported by GlobalMemoryStatus(Ex).
|
|
|
|
|
I am trying to develop IE toolbar in MFC using COM. On win7, the required dll (i.e. SelectorObjectAPI.dll) is present in %program files%\Microsoft\Internet Explorer Developer Toolbar\. But I am it is not there in XP SP3. I reinstalled IE 8 and result was same. Both m/c has IE 08.
Please Help!!!
|
|
|
|
|
|
Thanx... That Really helped
--
CHEERS!!!
|
|
|
|
|
|