Click here to Skip to main content
15,886,780 members
Home / Discussions / COM
   

COM

 
GeneralRational Rose Add-In, C++ Pin
Danoo27-Feb-08 22:19
Danoo27-Feb-08 22:19 
GeneralPlacement of CoInitializeEx call! Pin
rajandpayal27-Feb-08 5:34
rajandpayal27-Feb-08 5:34 
GeneralRe: Placement of CoInitializeEx call! Pin
User 21559727-Feb-08 8:48
User 21559727-Feb-08 8:48 
GeneralClass Object Release Pin
swjam26-Feb-08 19:51
swjam26-Feb-08 19:51 
GeneralRe: Class Object Release Pin
ThatsAlok26-Feb-08 22:12
ThatsAlok26-Feb-08 22:12 
GeneralRe: Class Object Release Pin
User 21559727-Feb-08 8:50
User 21559727-Feb-08 8:50 
GeneralRe: Class Object Release Pin
John M. Drescher7-Mar-08 23:03
John M. Drescher7-Mar-08 23:03 
GeneralVisual C++ Excel Addin causes Excel to crash Pin
ssaddi25-Feb-08 18:24
ssaddi25-Feb-08 18:24 
Hi all,

I am working on an application that is written in Java. It's basically a middleware server. The client is a Java application. However, there's a need to develop an Excel client. I have been provided with an addin that has certain functions that the VBA can call. The other side of the COM DLL is made of c++ programs that use JNI to pass data to Java and receive results. I have successfully created new functions to work on this.

When I started working on this I created a '|' delimited string to pass data from Excel to COM to Java and vice versa. The strings looked like this:
|Property1=Value1|Property2=Vaue2|........|PropertN=ValueN|

In the early stages these functions that I had created were simple atomic functions i.e. take in one string spit out resultant string. Now, however I need to be able to send arrays of such strings and also receive results in the form of arrays of strings.

I used CComSafeArray to do so.

Here's the code of what I did

STDMETHODIMP CAddin::MyClass_LoadVals(VARIANT ValIds, VARIANT* outVals)<br />
{<br />
<br />
USES_CONVERSION;<br />
std::list<std::string> result;<br />
std::list<std::string> inpArr;<br />
<br />
CComVariant var;<br />
<br />
CComSafeArray<bstr> parr;<br />
CComBSTR* bstrs;<br />
var.Attach(&valIds);<br />
parr.Attach(var.parray);<br />
<br />
int dim = parr.m_psa->cDims;<br />
if (parr.m_psa->cDims != 1)<br />
return S_FALSE;<br />
<br />
if(parr.m_psa->rgsabound->cElements > 1)<br />
{<br />
SafeArrayAccessData(parr,reinterpret_cast<void **="">(&bstrs));<br />
for (int i=0;i < parr.m_psa->rgsabound->cElements;i++)<br />
{<br />
std::string tmp;<br />
tmp = W2CA(bstrs[i]);<br />
inpArr.push_back(tmp);<br />
}<br />
}<br />
SafeArrayUnaccessData(parr.m_psa);<br />
<br />
VariantInit(outVals);<br />
<br />
if(JavaInterface::JavaInterface_LoadVals(inpArr,result)){<br />
outVals->vt=VT_ARRAY|VT_BSTR;<br />
createStringArrayVariant(outVals,result);<br />
return S_OK;<br />
}else{<br />
getCalypsoError();<br />
}<br />
<br />
return S_OK;<br />
}</void></bstr></std::string></std::string>



Code for createStringArrayVariant(VARIANT,std::list<std::string> :-
<br />
bool createStringArrayVariant(VARIANT* to, std::list<std::string>& from)<br />
{<br />
VariantInit(to);<br />
SAFEARRAYBOUND bound = {from.size(), 0};<br />
SAFEARRAY* array = ::SafeArrayCreate(VT_VARIANT, 1, &bound);<br />
<br />
long index = 0;<br />
VARIANT v; VariantInit(&v);<br />
for(std::list<std::string>::iterator i = from.begin(); i != from.end(); i++)<br />
{<br />
convertStringToVariant(&v, *i);<br />
::SafeArrayPutElement(array, &index, (void*)&v); ++index;<br />
}<br />
to->vt = VT_VARIANT | VT_ARRAY;<br />
to->parray = array;<br />
return true;<br />
}</std::string></std::string>


Please bear in mind that createStringArrayVariant(...) function was provided to me with the product that I am working on.

The resultant output is correctly passed to Excel. I load it as a variant array and try and do further processing. However, the problem is when the output is loaded, Excel starts crashing while doing simple things like updating values in the cells or running a simple loop. These parts of VBA code work fine in isolation i.e. without loading that array of values. Sometimes when Excel crashes, it just simply disappears without so much as an error report. My logs for the addin and the logs for Java, none of them indcate anything. Is the array too big or is this sort of programming not advisable for linking VBA and C++. I really need this to work. Any help would really be appreciated.

Please bear in mind that I have little experience with C++ and almost no exprience with Visual C++, prior to working on this project. Whatever I have learnt is from the existing code or Google, so I could be quite wrong with my code here.

I'd appreciate any leads in this matter.

Thanks for your help

Sukant Saddi
GeneralRe: Visual C++ Excel Addin causes Excel to crash Pin
Ernest Laurentin5-Mar-08 7:19
Ernest Laurentin5-Mar-08 7:19 
GeneralUsing C# managed DLL in C++ unmanaged code Pin
dany_ch20-Feb-08 23:26
dany_ch20-Feb-08 23:26 
AnswerRe: Using C# managed DLL in C++ unmanaged code Pin
ritz12344-Mar-08 23:10
ritz12344-Mar-08 23:10 
QuestionTrouble with using COM in Window Service Pin
kamal.chauhan18-Feb-08 21:14
kamal.chauhan18-Feb-08 21:14 
GeneralRe: Trouble with using COM in Window Service Pin
Garth J Lancaster18-Feb-08 21:45
professionalGarth J Lancaster18-Feb-08 21:45 
GeneralRe: Trouble with using COM in Window Service Pin
kamal.chauhan18-Feb-08 22:25
kamal.chauhan18-Feb-08 22:25 
QuestionHow to get Recycle Bin Files/folders name Pin
john563213-Feb-08 2:29
john563213-Feb-08 2:29 
GeneralExcel.WorksheetFunction.RTD - Did anyone know how to retrieve data programmatically from rtd server with callback function Pin
bangbangbigolo11-Feb-08 10:07
bangbangbigolo11-Feb-08 10:07 
GeneralReleasing Interface Pin
john56328-Feb-08 0:42
john56328-Feb-08 0:42 
GeneralRe: Releasing Interface Pin
CPallini8-Feb-08 4:41
mveCPallini8-Feb-08 4:41 
GeneralPlease need some help - Multiple Interface - activex control Pin
sv147-Feb-08 22:29
sv147-Feb-08 22:29 
GeneralProblem inregistring Com Class. Pin
Royaltvk7-Feb-08 20:08
Royaltvk7-Feb-08 20:08 
GeneralRe: Problem inregistring Com Class. Pin
User 2155978-Feb-08 0:48
User 2155978-Feb-08 0:48 
GeneralRe: Problem inregistring Com Class. Pin
Royaltvk18-Feb-08 18:23
Royaltvk18-Feb-08 18:23 
QuestionCoCreateInstance failing Pin
KellyR7-Feb-08 9:26
KellyR7-Feb-08 9:26 
GeneralRe: CoCreateInstance failing Pin
Royaltvk7-Feb-08 19:02
Royaltvk7-Feb-08 19:02 
QuestionRe: CoCreateInstance failing Pin
CPallini7-Feb-08 23:09
mveCPallini7-Feb-08 23:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.