Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.crashesgpfs,microsoft.public.excel.interopoledde,microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default How can I call Range::Find from C++ without crashing Excel?

I can call Range::Find from VBA - it works correctly, and requires only one
argument.

When I call it from C++, the function either throws an exception, or causes
a "Stack Corruption" error.

I am calling it with the following syntax:

Excel::_WorksheetPtr pWorksheet = Wb-Sheets-Item[1];

Excel::RangePtr pRangeSearch = pWorksheet-Cells;

Excel::RangePtr pRangeCurrent = pRangeSearch-Find("MKV", _variant_t(),
_variant_t(),
_variant_t(), _variant_t(), Excel::xlNext, _variant_t(),
_variant_t());

Is there anything I'm doing wrong?

Thanks,
Aaron Queenan.


  #2   Report Post  
Posted to microsoft.public.excel.crashesgpfs,microsoft.public.excel.interopoledde,microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How can I call Range::Find from C++ without crashing Excel?

In VBA, the method returns NOTHING (uninitialized object) if the target is
not found. Would that cause the error you are getting?

--
Regards,
Tom Ogilvy

"Aaron Queenan" wrote in message
...
I can call Range::Find from VBA - it works correctly, and requires only

one
argument.

When I call it from C++, the function either throws an exception, or

causes
a "Stack Corruption" error.

I am calling it with the following syntax:

Excel::_WorksheetPtr pWorksheet = Wb-Sheets-Item[1];

Excel::RangePtr pRangeSearch = pWorksheet-Cells;

Excel::RangePtr pRangeCurrent = pRangeSearch-Find("MKV",

_variant_t(),
_variant_t(),
_variant_t(), _variant_t(), Excel::xlNext, _variant_t(),
_variant_t());

Is there anything I'm doing wrong?

Thanks,
Aaron Queenan.




  #3   Report Post  
Posted to microsoft.public.excel.crashesgpfs,microsoft.public.excel.interopoledde,microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default How can I call Range::Find from C++ without crashing Excel?

I don't know what's causing the error - Range::Find never returns, but about
10 seconds after calling it, I get either a stack frame corruption error
(something about the base pointer not being preserved across a function
call), or an exception. All of the arguments I'm passing as _variant_t()
are optional.

Aaron.

"Tom Ogilvy" wrote in message
...
In VBA, the method returns NOTHING (uninitialized object) if the target is
not found. Would that cause the error you are getting?

--
Regards,
Tom Ogilvy

"Aaron Queenan" wrote in

message
...
I can call Range::Find from VBA - it works correctly, and requires only

one
argument.

When I call it from C++, the function either throws an exception, or

causes
a "Stack Corruption" error.

I am calling it with the following syntax:

Excel::_WorksheetPtr pWorksheet = Wb-Sheets-Item[1];

Excel::RangePtr pRangeSearch = pWorksheet-Cells;

Excel::RangePtr pRangeCurrent = pRangeSearch-Find("MKV",

_variant_t(),
_variant_t(),
_variant_t(), _variant_t(), Excel::xlNext, _variant_t(),
_variant_t());

Is there anything I'm doing wrong?

Thanks,
Aaron Queenan.






  #4   Report Post  
Posted to microsoft.public.excel.crashesgpfs,microsoft.public.excel.interopoledde,microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default How can I call Range::Find from C++ without crashing Excel?

First of all for all the optional parameters that you don't use pass
vtMissing.
pRangeSearch-Find("MKV", vtMissing ...

Then make sure all the smart pointers wrap a valid interface pointer. You
should
always do something like this:
Excel::_WorksheetPtr pWorksheet = Wb-Sheets-Item[1];
ATLASSERT(pWorksheet != 0); // if called from atl code

Where do you use the given code? Could there be an issue with the calling
convention?


"Aaron Queenan" wrote in message
...
I can call Range::Find from VBA - it works correctly, and requires only

one
argument.

When I call it from C++, the function either throws an exception, or

causes
a "Stack Corruption" error.

I am calling it with the following syntax:

Excel::_WorksheetPtr pWorksheet = Wb-Sheets-Item[1];

Excel::RangePtr pRangeSearch = pWorksheet-Cells;

Excel::RangePtr pRangeCurrent = pRangeSearch-Find("MKV",

_variant_t(),
_variant_t(),
_variant_t(), _variant_t(), Excel::xlNext, _variant_t(),
_variant_t());

Is there anything I'm doing wrong?

Thanks,
Aaron Queenan.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where can I find a Outside Sales Daily Call Report Template? Paul Excel Discussion (Misc queries) 1 April 20th 10 04:03 PM
SUMPRODUCT - MATCH CALL DETAILS 2 FIND RELEVANT EXTN - URGENT PLS! Twiggy Excel Discussion (Misc queries) 0 February 22nd 10 07:31 PM
Why can't I call a range of cells 'c'? Jock Excel Discussion (Misc queries) 3 April 30th 09 03:29 PM
call range by cell value Roland Excel Worksheet Functions 1 January 15th 09 04:32 PM
returning ranges offset from argument range function call Peter Williams Excel Programming 5 February 8th 04 11:59 PM


All times are GMT +1. The time now is 07:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"