krishnasamy

Hi,

I am retrieving the image from DLL through vc++ dll. Actually Image is retrieving in Callback function of main function. When I writing that image file inside of the Callback function then no problem in retrieving. At the same I want to send the Imagedata to the another function and write the same which cause the error.

Here I given that code,

//Callback function

prResponse prSTDCALL MyGetFileDataFunction(

prHandle CameraHandle,

prObjectHandle ObjectHandle,

prContext Context,

prProgress* pProgress

)

{

static ofstream out("capture.jpg", ios:Surpriseut|ios::binary);

switch( pProgress->lMessage )

{

prUInt8 imgbuffer[1024];

case prMSG_DATA_HEADER:

break;

case prMSG_DATA:

for (prUInt32 index = 0; index < pProgress->lLength; index++)

{

imgbuffer[index] = pProgress->pbData[index];

}

PowershotDll:Stick out tongueowershotSdkDll::Copy(imgbuffer,pProgress->lLength); //Calling another function and send the data

memcpy(CaptureImage,imgbuffer,1024L);

out.write((const char*)CaptureImage,1024L);

break;

case prMSG_TERMINATION:

out.close();

break;

}

return prOK;

}

Copy function:

void PowershotSdkDll::Copy(prUInt8 *pDataBuffer, prUInt32 dataLength)

{

// Byte managedDataBuffer __gc[] = new System::Byte[dataLength];

BYTE managedDataBuffer[1024];

for (prUInt32 index = 0; index < dataLength; index++)

{

managedDataBuffer[index] = pDataBuffer[index];

}

/// Write the data to the memoryStream

//pMemoryStream->Write(managedDataBuffer, 0, dataLength);

static ofstream out1("Copycapture.jpg", ios:Surpriseut|ios::binary|ios::app);

out1.write((const char*)managedDataBuffer, 1024L);

out1.close();

}

I got the image capture.jpg but i didnt get the copycapture.jpg image which contain only 1024 bytes.

Pleae give your suggestion.



Re: Visual C++ General Problem in Image Retrieving

Ramkrishna Pawar

Well what do you expect when you create file everytime you get callback You need to append the packets you get to the file untill the transmission is complete, so may be you can declare your ofstream object global, open it once and for each callback write data to it, close it when you see the callback for 100%.






Re: Visual C++ General Problem in Image Retrieving

Ramkrishna Pawar

You can also open file for editing (if you want to open it each time).

ios_base:Surprisepenmode (Standard C++ Library)




Re: Visual C++ General Problem in Image Retrieving

krishnasamy

Thanks for your reply.

I need to bring the image data to the outside of the function. So I sent the data to the another function and write.

I do the same in Exe. When I tracing the code, the cursor move to another function with data and store it in byte array. But the image not displayed. I think that array data has not re-initialized.

So I need to know that how to re-assign that array and store that data.

Same as done in c# using Memorystream.write method. Can you suggest same in c++





Re: Visual C++ General Problem in Image Retrieving

Ramkrishna Pawar

Looking at your code, I see a lot of unnecessory things, such as copying the reced data, you can just pass the recvd pointer as is, also I would suggest using Win32 Or CRT File API instead of streams, they give much better performance.






Re: Visual C++ General Problem in Image Retrieving

krishnasamy

Thanks for your reply.

Actually I have created the Dll with image creation inside of the dll function. When I invoke the Dll from java and displaying that image in screen. At that time image retrieving takes 50 more seconds to display. So that is my problem.

I need to send that full byte array data to the Java function and write image file in java. In Dll, the callback function calls repeteadly still full image capture. Each time retrieve 1024bytes from SDK library. So I need to append the data in memory stream of each time. Then only I send the full image data to the java function.

Can we write the data through the file only why not in memory stream

Please give your kind of suggestion.





Re: Visual C++ General Problem in Image Retrieving

Ramkrishna Pawar

Once you have the data, store and send it in whatever way you want, there is not restriction on it.




Re: Visual C++ General Problem in Image Retrieving

krishnasamy

If it is not restriction then why not retrieve that data to another function. I got the last block(1024) image data only.

How I write the data to the memory stream in contrinously





Re: Visual C++ General Problem in Image Retrieving

Ramkrishna Pawar

What memory stream I thought your problem was regarding writing data to file, is that solved






Re: Visual C++ General Problem in Image Retrieving

krishnasamy

Writing the data inside of the callback function is working proberly. But When I try to write the data outside of the callback function that cause the problem.

Now I have changed my function as follows,

Default declaration:
static ofstream out("capture.jpg", ios:Surpriseut|ios::binary);

void PowershotSdkDll::Copy(prUInt8 *pDataBuffer, prUInt32 dataLength)
{
out.write((const char*)pDataBuffer, dataLength);
out.close();

}

In Callback function:

prResponse prSTDCALL MyGetFileDataFunction(
prHandle CameraHandle,
prObjectHandle ObjectHandle,
prContext Context,
prProgress* pProgress
)
{
/* Display progress */
switch( pProgress->lMessage )
{
case prMSG_DATA_HEADER:
break;
case prMSG_DATA:
PowershotDll:Stick out tongueowershotSdkDll::Copy(pProgress->pbData,pProgress->lLength);
break;
case prMSG_TERMINATION:
break;
}
return prOK;
}


But I have retrieved the last block(1024) image data only. What is the problem





Re: Visual C++ General Problem in Image Retrieving

Ramkrishna Pawar

Dude, you are closing the file in Copy function, that will only recv first 1024 bytes.

You need to write the data to file each time you recv untill you get termination message.






Re: Visual C++ General Problem in Image Retrieving

krishnasamy

Still I couldn't solve the problem. So I have changed function as write the "capture.jpg" image to the Callback function and read that "Capture.jpg" image data in another function and send it to java function.

Here I mentioned code,

prResponse prSTDCALL MyGetFileDataFunction(

prHandle CameraHandle,

prObjectHandle ObjectHandle,

prContext Context,

prProgress* pProgress

)

{

/* Display progress */

fstream binary_file("capture.jpg",ios:Surpriseut|ios::binary|ios::app);

switch( pProgress->lMessage )

{

case prMSG_DATA_HEADER:

break;

case prMSG_DATA:

binary_file.write((const char*)pProgress->pbData,1024L);

break;

case prMSG_TERMINATION:

binary_file.close();

PowershotDll:Stick out tongueowershotSdkDll::RetByteFullImg();

break;

}

return prOK;

}

Another function such RetByteFullImg:

BYTE* PowershotSdkDll::RetByteFullImg()

{

char * mybuffer;

long size;

ifstream infile ("capture.jpg",ifstream::binary);

// get size of file

infile.seekg(0,ifstream::end);

size=infile.tellg();

infile.seekg(0);

// allocate memory for file content

mybuffer = new char [size];

mycaptureData = new BYTE[size];

// read content of infile

infile.read (mybuffer,size);

memcpy(mycaptureData,mybuffer,size);

// release dynamically-allocated memory

delete[] mybuffer;

infile.close();

return MyCaptureData;

}

In above code memcpy has not working proberly. Why because size of the image too large(1.12MB).

How could I copy the bulk amout of data using memcpy .

Can You suggest





Re: Visual C++ General Problem in Image Retrieving

Ramkrishna Pawar

1.12 MB is not too large, have you tried debugging Does your size variable read correct file size

Also, when you already have the data in mybuffer, why do you want to create copies Why not return pointer to mybuffer






Re: Visual C++ General Problem in Image Retrieving

krishnasamy

Yes. I tried. I got correct size of the image.

Actually our java team could not read the Pointer type. So I need to convert pointer data to byte array data. After converting the byte array data I will send to java function.

Thatswhy I convert the pointer to byte array.

If I can to send the data from callback function to outside of the function then all the problem should be solve. But I didn't solve that problem.

Please suggest me.





Re: Visual C++ General Problem in Image Retrieving

Ramkrishna Pawar

The char pointer and byte pointer are same, for Java it should look totally same.

You can have whatever type for the mybuffer variable, the point is, you dont need to allocate 2 diff mem chuncks, just allocate one of right type.