Using GdPicture in MFC

Discussions about GdPicture.NET usage in non managed applications built in vb6, Delphi, vfp, MFC c++ etc...
Post Reply
AllanS
Posts: 8
Joined: Thu May 16, 2013 2:46 am

Using GdPicture in MFC

Post by AllanS » Fri Oct 11, 2013 4:38 am

I am trying to use CGdPictureImaging class in MFC and having trouble
I have GdPicture.NET.9

I installed the program, then registered the dll using framework 2.0 and created the tlb.
Then I generated the CLicenseManager and CGdPictureImaging classes from the tlb.
So far so good.

Then I tried the following code:

CLicenseManager* pLicenseManager = new CLicenseManager();
pLicenseManager->RegisterKEY(the_license_key);
CGdPictureImaging* pGdImaging = new CGdPictureImaging();
long lImageID = pGdImaging ->CreateGdPictureImageFromFile(path_of_the_photo);
long lError = pGdImaging ->GetStat();
pGdImaging ->ReleaseGdPictureImage(lImageID);

the lImageID and lError returned by both functions would be -858993460, and I'm not sure what steps I missed.
I am not sure if I actually need to instantiate a new class with GdPicture in COM, but I tried both instantiating and without.
I did realized the m_lpDispatch inside the classes are 0, but I'm not sure how to fix that.

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: Using GdPicture in MFC

Post by Cedric » Wed Oct 16, 2013 3:40 pm

Hello Allan,

The way you are creating the objects is wrong. Here is what you should be doing:

Code: Select all

CLicenseManager pLicenseManager;
pLicenseManager.CreateDispatch(L"GdPicture10.LicenseManager");
pLicenseManager.RegisterKEY(L"XXXX"); // Please replace XXXX with your license key

CGdPictureImaging pGdImaging;
pGdImaging.CreateDispatch(L"GdPicture10.GdPictureImaging");
long lImageID = pGdImaging.CreateGdPictureImageFromFile(L"D:\test.jpg");
long lError = pGdImaging.GetStat();
pGdImaging.ReleaseGdPictureImage(lImageID);
Cheers!

AllanS
Posts: 8
Joined: Thu May 16, 2013 2:46 am

Re: Using GdPicture in MFC

Post by AllanS » Thu Oct 17, 2013 4:08 am

Thanks! That works.
So i'm trying to mess around with the program more and having trouble.

CGdPictureImaging.CreateGdPictureImageFromByteArray(SAFEARRAY** Data)

This takes in a SafeArray, below is my code.
When I ran it, the function returns "the parameter is incorrect".
I'm developing in VS 2005, that's why I'm using COleSafeArray instead of CComSafeArray

CGdPictureImaging gdImaging;
gdImaging.CreateDispatch(_T("GdPicture9.GdPictureImaging"));
COleSafeArray saPhoto;
// lSizeOfMyByteArray is long and lpMyByteArray is BYTE FAR*
saPhoto.CreateOneDim(VT_UI1, (DWORD)lSizeOfMyByteArray, lpMyByteArray); // I've tried VT_I4 as well
LPSAFEARRAY psa = NULL;
saPhoto.Copy(&psa);
long lImageID = gdImaging.CreateGdPictureImageFromByteArray(&psa);

I'm also trying to save the resulting image into memory, would you recommend using SaveAsStream or SaveAsByteArray?
I see that SaveAsStream outputs LPDISPATCH, how do I go about converting that into a usable format?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest