ImageMagickObject seems to be non-responsive
Posted: 2008-10-30T12:19:54-07:00
I've used the code from MagicCMD.cpp to create a small test app that bascially removes all command options except for Identify and Convert.
The function calls are succeeding without errors, however I am not getting a result from the function calls to Identify.
Input args are:
identify "path_to_image.png" -format "%x x %y"
Please note that the only changes I have made from the code in MagicCMD.cpp is that I am #importing the dll instead of the tlb... and I have removed all other commands from the struct and from the code below. The only commands that remain are Identify and Convert.
The purpose is to nab the density of the image, and using convert to resize to a percentage of the current density.
I figured I would try some sanity tests with just Identify to start though.
For reference, I am using Visual Studio 2008 as my dev studio. OS is Windows, but that is obvious
Any advice or pointers are welcome, thanks in advance
Code snippet in question is as follows:
The function calls are succeeding without errors, however I am not getting a result from the function calls to Identify.
Input args are:
identify "path_to_image.png" -format "%x x %y"
Please note that the only changes I have made from the code in MagicCMD.cpp is that I am #importing the dll instead of the tlb... and I have removed all other commands from the struct and from the code below. The only commands that remain are Identify and Convert.
The purpose is to nab the density of the image, and using convert to resize to a percentage of the current density.
I figured I would try some sanity tests with just Identify to start though.
For reference, I am using Visual Studio 2008 as my dev studio. OS is Windows, but that is obvious
Any advice or pointers are welcome, thanks in advance
Code snippet in question is as follows:
Code: Select all
int main(int argc, char* argv[])
{
int
index,
status = 0;
char
*name;
CommandType
code = cmdUnknown;
// We must have at least a command, input, and output
if (argc < 4)
return 0;
index = 1;
while ((name = Commands[index].name))
{
if (stricmp(name,argv[1]) == 0)
{
code = Commands[index].code;
break;
}
index++;
}
if (code == cmdUnknown)
return 0;
CoInitialize(NULL);
try
{
CComVariant
result;
SAFEARRAY
**ppsa = (SAFEARRAY**) NULL;
IMagickImagePtr pImageProc(__uuidof(MagickImage));
if (pImageProc == NULL)
status = 1;
else
{
{
// Define the array bound structure
CComSafeArrayBound bound[1];
bound[0].SetCount(argc-2);
bound[0].SetLowerBound(0);
CComSafeArray<VARIANT> args(bound);
if( !args )
status = 2;
else
{
for(index = 2; index < argc; ++index)
{
CComVariant vt(argv[index]);
HRESULT hr = vt.Detach(&args[index-2]);
}
switch(code)
{
case cmdConvert:
result = pImageProc->Convert(args.GetSafeArrayPtr());
break;
case cmdIdentify:
result = pImageProc->Identify(args.GetSafeArrayPtr());
break;
}
pImageProc.Release();
}
}
}
}
catch(_com_error ex)
{
HRESULT
res = ex.Error();
_bstr_t
desc = ex.Description();
printf("Error %s (0x%08x)\n",(char *)desc,res);
status = 4;
}
CoUninitialize();
return status;
}