-
April 6th, 2010, 12:21 PM
#1
Interesting Issue when using ActiveX Com in C++
HI All,
i've been facing a really frustrating, interesting and mindwrenching issue in my native code. Here is a background.
1. I was given a thirdparty ACtiveX OCX file that needed to be called through JAva.
2. I wrote a C++ JNI wrapper to call the methods of the activex object.
3. I first initialize the object, set the relevant parameters (sent from java) and then call the method I need.
4. For every record, I need to perform step 3. NOw, I am ryuning batch loads. THE code works fine for 9500 records. BUt, once the record count reaches 9885, I get a pop-up error from the activeX OCX control. I've not coded that pop-up. It comes out of the blue.
please dont get distracted because callign from Java does not seem to be the issue because the error comes from the activeX control.
I initially thought that it could be a memory issue, but even after doubling my VM Memory allocation, I get the error. Its not a data issue, because the reocrd that causes the issue, if I run the code just for that single record, it works fine.
Below is the implemetnation of the C++ code. LEt me know if I'm doign somethign wrong or if someone has seen something like this happen before. WHAt is baffling is that it works smoothly for less records. When the pop up appears, no exception is caught on the native side also.!!!
I'm running on windows, so is it possible to trace the internal malloc and release within the dLL?
ANy thoughts and ideas will help. I've been struggling for about three days now.
#include "stdafx.h"
#include "jni.h"
#import "thirdparty.ocx" raw_native_types
JNIEXPORT jstring JNICALL Java_org_nik_integration_test_Exporter_saveAsImage
(JNIEnv * env, jobject obj, jint height, jint width , jstring fileName, jstring encryptionKey, jshort encryptionAlgorithm, jstring encryptedImage, jshort imageType)
{
const char* fName = NULL;
const char* encryptionKeyc = NULL;
const char* encImgc = NULL;
ThirdPartyLib::_DTPPtr tpptr = 0;
HRESULT hres = 0;
try
{
hres = ::CoCreateInstance(__uuidof(ThirdPartyLib::TP),NULL,CLSCTX_ALL, __uuidof(ThirdPartyLib::_DTP), (void**)&tpptr);
//Retrieve values sent from Java
fName = env->GetStringUTFChars(fileName,0);
encryptionKeyc = env->GetStringUTFChars(encryptionKey,0);
encImgc = env->GetStringUTFChars(encryptedImage,0);
tpptr->Key = _com_util::ConvertStringToBSTR(encryptionKeyc);
tpptr->Algorithm = encryptionAlgorithm;
tpptr->Img = _com_util::ConvertStringToBSTR(encImgc);
tpptr->SaveUnencrypted(width, height,_com_util::ConvertStringToBSTR(fName) , 1);
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf( "Exception thrown for classes generated by #import" );
printf( "\tCode = %08lx\n", e.Error());
printf( "\tCode meaning = %s\n", e.ErrorMessage());
printf( "\tSource = %s\n", (LPCTSTR) bstrSource);
printf( "\tDescription = %s\n", (LPCTSTR) bstrDescription);
// Errors Collection may not always be populated.
if( FAILED( hres ) )
{
printf( "*** HRESULT ***" );
}
return NULL;
}
__finally
{
tpptr->Release();
tpptr = NULL;
//Release memory - java specific
env->ReleaseStringUTFChars(encryptionKey, encryptionKeyc);
env->ReleaseStringUTFChars(ink, inkc);
env->ReleaseStringUTFChars(fileName, fName);
}
-
April 6th, 2010, 02:31 PM
#2
Re: Interesting Issue when using ActiveX Com in C++
Doubling your virtual memory does nothing. If your application uses more then 2MB, it will run out of memory. You'll need to profile it to know exactly, or just watch your process' memory usage in the task manager. This is rough, but it'll let you know if it could be a memory/resource issue.
Viggy
-
April 7th, 2010, 04:40 AM
#3
Re: Interesting Issue when using ActiveX Com in C++
I wonder how did yo mange to compile having try-catch with __finally.
Code:
E:\Temp\542>cl 542.cpp /EHsc
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
542.cpp
542.cpp(12) : error C3273: '__finally' : not allowed on C++ try block
Best regards,
Igor
-
April 7th, 2010, 02:06 PM
#4
Re: Interesting Issue when using ActiveX Com in C++
Originally Posted by nikhil.gonsalves
4. For every record, I need to perform step 3. NOw, I am ryuning batch loads. THE code works fine for 9500 records. BUt, once the record count reaches 9885, I get a pop-up error from the activeX OCX control. I've not coded that pop-up. It comes out of the blue.
I might have coded that popup. Could you show us the popup so I could see if it's one of mine?
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
|