ImagePro>Re: Can a IPBasic macro call a Macro made with theSDK?


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ImagePro>Re: Can a IPBasic macro call a Macro made with theSDK?



Thanks,

this was a big help.  I was almost finished using the marshalling technique
in the VC++ wizard.  I could get it to work, but I somehow screwed up the
function names - Id matching so that when you called one function, you got
another.  It has to do with how they all come through 1 interface where they
define some reference value for each function and I think I screwed up the
reference mapping in some non-source (not in .cpp or .h) code that I
couldn't figure out.

In any case, I got your approach to work.  This is great.  It still took me
a while to realize I had to add the function to the .def file for it to be
exported.  I had a __declspec(dllexport) of the function defintion, but this
didn't seem to work.
Taking your example and adding the func to the .def and I was in business.
Having to call those arrays with a (0) appended was another hurdle that the
manual cleared up.

Many Thanks.

Mike Plonski

-----Original Message-----
From: Image-Pro Plus Users Email List
[mailto:imagepro-users@lists.mediacy.com]On Behalf Of Stan Voynick
Sent: Thursday, November 15, 2001 2:11 PM
To: Image-Pro Plus Users Email List
Subject: ImagePro>Re: Can a IPBasic macro call a Macro made with theSDK?


Mike:

   The situation can actually be a little simpler than this, *if* you
can accept one important constraint: that you don't intend to use your
"C" functions from Visual Basic programs (i.e. that you will use them
only from IPBasic macros running under ImagePro Plus.)  If this is the
case then you can eliminate the marshalling issue and the interaction
with MacroExecFunction.   Here's how I do it; I'll run you through an
example of a function I call IpArrayStats().

I declare the function prototype something like this, using 'extern
"C"' because I'm compiling my project as C++ code.:

#############################################################
#################  "C" declaration #########################
extern "C"
{
   short int WINAPI
      IpArrayStats( short int docId,
                    short int maskId,
                    LPFLOAT statsArray);
}
#############################################################

Note my explicit use of "short int", which matches the "Integer" type
in IPBasic.  This way, in my macros, I can use the familar IPBasic
form of

ret = IpArrayStats( ... )

   I also used the short int type for the document identifiers of two
images that are passed, since doc ID's are "Integers" in IPBasic.

Now, to code the actual function is probably pretty obvious:

#############################################################
#################  "C" code  ###############################
short int WINAPI
IpArrayStats(short int docId,short int maskId,LPFLOAT statsArray)
{
   IMHANDLE docVri = 0;
   IMHANDLE maskVri = 0;
   IMINST ImgInstance = 0;
   IMINST MaskInstance = 0 ;

   bool doMask = (maskId >= 0);

   short int siVri ;

   IpDocGet(GETDOCVRI, docId, &siVri);
   docVri = (IMHANDLE)siVri;
   if (doMask)
   {
      IpDocGet(GETDOCVRI, maskId, &siVri);
      maskVri = (IMHANDLE)siVri;
   }

   if (docVri < 0)
      return -1;
   if ( doMask && (maskVri < 0) )
      return -2;

   //****************************
   // do your useful stuff here.
   //****************************

   HWND hWndParent = (HWND)0xFFFFFFFF;
   IpAppGet(GETAPPWND,0,&hWndParent);
   IPCX_RECORDLINE(hWndParent, "' Dim StatsArray(12) As Single");
   IPCX_RECORD(hWndParent, "IpArrayStats(DOCSEL_ACTIVE, MaskId,
StatsArray(0))");
   return 0;  // my convention for success
}

#############################################################

Since it applies to crossover use of IPBasic and "C" functions, I've
included in this example my code that converts from IPBasic docID
values (which are 16-bit IPBasic "Integers) to IMHANDLE values usable
with HIL and HAIL calls (which are 32-bit values in the "C" world, if
you go look up the IMHANDLE #define.)  It's basically a forced casting
of the 16-bit docID to the 32-bit IMHANDLE value, and it works in
practice.  I confirmed that it's an appropriate way to do things with
Jean-Paul Martin when he was still with Media, and he said that it
would work fine except in one extreme case (opening up a cumulative
total of more than 32767 images without having all images closed at
some point, which "resets" the docID counter to zero again.)

Notice that I also included my "macro recording" lines at the end
there.  I haven't used the PfxRecordXxxx functions yet, as the IPCX_
macros seem to work fine for me.  RECORDLINE records, verbatim,
whatever you put in there.  I think I recall that RECORD puts a
"ret = " before the function name - per the familiar IPBasic
convention.

Now, this function is one that can reasonably be used from the IPWin
menu interface, so I have an entry in my interface function "switch"
statement something like:

#############################################################
#################  "C" code  ###############################

case 103:
   ret = IpArrayStats(DOCSEL_ACTIVE, DOCSEL_NONE, StatsArray);
   if ( ret )
   {
      sprintf(str,"Problem calculating array statistics; return code
%d",ret);
      ::MessageBox(passedHWndApp,str,"SeqAverageFloat",MB_OK);
   }
   else
   {
      sprintf(str,"Mean:  %f, %f\r\nSdev:  %f, %f\r\nMin:   %f,
%f\r\nMax:   %f, %f\r\nIncl:   %f, %f\r\nExcl:   %f, %f",
         StatsArray[0],StatsArray[1],StatsArray[2],StatsArray[3],
         StatsArray[4],StatsArray[5],StatsArray[6],StatsArray[7],
         StatsArray[8],StatsArray[9],StatsArray[10],StatsArray[11]  );
      ::MessageBox(passedHWndApp,str,"Array Statistics",MB_OK);
   }
   break;
#############################################################

... and then I put an appropriate line in IPWIN32.MNU to create the
menu item and refer it to this module and ID #103 in the interface
function.

Than as your last step, you provide a declaration in a ".BAS" file so
that when IPBasic wakes up, it knows where to find your function when
it comes across it in a macro.  For the function I've shown above, the
syntax would be:

#############################################################
#################  IPBasic declaration ######################

Declare Function IpArrayStats Lib "STIUtils" (ByVal docId%, ByVal
maskId%, statsArray!) As Integer

#############################################################

(Instead of the '%' and '!' characters, you could type out "As
Integer" and "As Single", respectively.)

This is all on one line in the .BAS file.  For my purposes, I leave
the Media-provided IPC32.BAS file alone, unmodified, and I just
include my own file (in my case, named IPSTI.BAS) in which I put all
my declarations, including any constants I want to make available to
IPBasic.  As long as this .BAS file is in the IPWin4\Bas directory,
IPWin seems to find it just fine at startup, and everything works OK.

Finally, to reiterate, these steps are useful only if you *DO NOT*
intend to use your function from Visual Basic.  If you intend to do
that, you have to get into the marshalling stuff explained in Dan's
Email below.

I suggest you subscribe to the SDK mailing list, as that's a good
place for SDK programming questions.  See

http://www.mediacy.com/sdkpg.htm

and there's a link near the bottom of the page to subscribe.

Regards,

   - Stan -

--
------------------------------------------------------------------


Christian Briere wrote:
>
> Hi Mike,
>
> Here is below the response to a question that I posted a few months ago
and
> which concern a similar problem.
> Hope this will help
>
> To: <imagepro-users@lists.mediacy.com> (Image-Pro Plus Users Email List)
> From: "Dan Satria" <dsatria@erols.com>
> Subject: ImagePro>Re: IPP Plug-in
> Date: Mon, 25 Jun 2001 22:39:04 -0400
> X-Original-Message-ID: <OMEBJODDODLHIJBAALAAKEKPCCAA.dsatria@erols.com>
>
> Hi all,
>
> Since no one answer this question, I am going to try to recall from my
> deep long term memory of how the macro works, so bear with me for any
> omission or error.
>
> The SDK Wizard gives you the option of creating functions that can be
> called from AutoPro macro.  If you skipped this option while creating
> your plug-in, you may want to either create a new plug-in with Auto-Pro
> support and port your plug-in into the new plug-in, or create a new
> plug-in with Auto-Pro function support and follow how it is done and
> retrofit your existing plug-in.  The latter is probably more daunting
> since there are just too many files involved to add the support after
> the plug-in is created.  The former is better since you will have a
> working model that you can tweak.
>
> In general you need to look at the following files:
>
> ipxxxx.def export the functions at DLL level.  Auto-Pro functions are C
> functions.
>
> ipxxxx.bas declares the functions in VB syntax so that AutoPro engine
> can recognize it.
>
> ipcxxxx.h  declares the functions in C syntax.  This file is processed
> by makebas.bat batch file to create ipxxxx.bas.   This file is included
> in both the main header file and in the task1.h file.   The main header
> file makes the function exportable as C function.  The task1.h makes
> the function a member of CmPluginTask1.
>
> task1dlg.cpp - To make the plug-in records your Auto-Pro function, you
> need to add the recording portion in the task1dlg.cpp.  This example
> records the "hide" function when the plug-in dialog is closed.
> void CmTask1Dlg::OnClose()
> {
>         PfxRecordFunction("IpXxxxShow(0)");
>
> -----------------------
> The first entry into each Auto-Pro function is in macro1.cpp.
> IPCERROR WINAPI
> IpXxxxShow(short bShow)
> {
>         AFX_MANAGE_STATE(AfxGetStaticModuleState());
>         IPCPARAM        IpP;
>         _IPCSETUP1(IpP, (long)bShow, ARG_VAL, 0);
>         _MYIPCEXIT(IpP, IP_XXXX_SHOW);
> }
>
> After marshalling the arguments (using _IPCSETUP1), it calls _MYIPCEXIT
> where it routes the call to Image-Pro exe and end up in
> MacroExecFunction1 (usually at the top of macro1.cpp).
> MacroExecFunction1 simply redirects the call to the
> CmPluginTask1::Ipxxxx member functions.
>
> IPCERROR
> CmPluginTask1::IpXxxxGet(short sAttribute, short sParam, LPVOID
> lpParam)
>
> This is where you want to code your function.
>
> I hope this give you some direction.
>
> Dan Satria
> Graha Logica, Inc.
> dsatria@erols.com
>
> A 19:13 14/11/01 -0800, vous avez écrit :
> >
> >Is there a way to call macros that are made in C using the SDK kit from
> >within IPBasic.
> >
> >I tried to record a macro where I selected items from menus that were
made
> >using the SDK;
> >If it was a macro made with the MFC SDK template, it would record an
> >incorrect name with an argument of 1.  If you then try to run the macro
it
> >generates an error.
> >
> >If it was a simple macro - like the SDK simple C example, nothing gets
> >recorded when you call the macro from the pulldown menu.
> >
> >It seems like there should be a way to generate a menu pulldown call from
> >IPbasic.
> >
> >My problem, it seems like there is no way to fully automate a task - 1
click
> >using a combination of SDK generated C routines and IPBasic macros.
> >
> >The C routines can't call the IPBasic Macros and vice-versa?  I didn't
find
> >anything in the SDK about calling user defined macros.  It does have some
> >routines _IPCCALL (etc.) to allow the C-code to call IP functions, but it
> >doesn't have a complete working example (like a MS project file).  It
also
> >seems like this only can call native IPfunction and not IPBasic macros.
I
> >would be more interested in having my IPBasic function being able to call
> >some generic C routine with generic arguments that can be passed.  The
> >IpMail example in the SDK alludes to this, but again it is not complete.
It
> >seems like there should be a way to do this, as the SDK has a means to
have
> >a pull down menu call a C function.
> >
> >It seems like if there is a way to do it with clicking items, you should
be
> >able to do it in code.  Are there any automated tools for converting
IPBasic
> >Auto-Pro macros to C Auto-Pro calls.  Several times in the documentation
it
> >suggests, you prototype things in IPBasic interface to AutoPro and then
you
> >can write it in C interface to AutoPro later for more flexibility.  Some
of
> >the samples even say this was done in IPBasic and then ported to C.
THere
> >should at least be some way to call the "Interfacefunction" from IPBasic
in
> >a way similiar to what happens when it gets called from a pull down menu.
> >
> >Is there some Auto-Pro manual that I am missing.  The SDK help files seem
to
> >refer to manual chapters for more detail, but I don't have / know what
> >manual they are referring to.  THe "Auto-Pro Guide for windows" (table on
> >page 7-3) refers to a "Getting started with Auto-Pro" disk that I didn't
see
> >in my package.
> >
> >Any suggestions as to how I can combine IPBasic and C Auto-Pro without
> >having the user having to click everything.
> >
> >Mike Plonski
> >
> >
> >
> >***********************************************************
> >Need an Image-Pro macro or driver? Find it at
http://www.Solutions-Zone.com
> >Got an Image-Pro macro or driver? Add it to http://www.Solutions-Zone.com
> >***********************************************************
> >
> >This message is sent to you because you are subscribed to
> <imagepro-users@lists.mediacy.com>.
> >To unsubscribe, email to: <imagepro-users-off@lists.mediacy.com>
> >To switch to the DIGEST mode, email to
> <imagepro-users-digest@lists.mediacy.com>
> >To switch to the INDEX mode, email to
> <imagepro-users-index@lists.mediacy.com>
> >Send administrative queries to
<imagepro-users-request@lists.mediacy.com>
> >To subscribe or unsubscribe visit
> http://www.solutions-zone.com/ipednld/subscriber.asp
> >
> ---------------------------------------------------------------------
> Christian BRIERE                           e-mail: briere@ensat.fr
> Lab. BAP - ENSAT                                  Tel.: (33)05 62 19 35 90
> Pôle de Biotechnologie végétale               Fax.: (33)05 62 19 35 89
> 18, Chemin de Borderouge - BP 107 Auzeville tolosane
> 31326 CASTANET-TOLOSAN - France
>
> ***********************************************************
> Need an Image-Pro macro or driver? Find it at
http://www.Solutions-Zone.com
> Got an Image-Pro macro or driver? Add it to http://www.Solutions-Zone.com
> ***********************************************************
>
> This message is sent to you because you are subscribed to
<imagepro-users@lists.mediacy.com>.
> To unsubscribe, email to: <imagepro-users-off@lists.mediacy.com>
> To switch to the DIGEST mode, email to
<imagepro-users-digest@lists.mediacy.com>
> To switch to the INDEX mode, email to
<imagepro-users-index@lists.mediacy.com>
> Send administrative queries to  <imagepro-users-request@lists.mediacy.com>
> To subscribe or unsubscribe visit
http://www.solutions-zone.com/ipednld/subscriber.asp

***********************************************************
Need an Image-Pro macro or driver? Find it at http://www.Solutions-Zone.com
Got an Image-Pro macro or driver? Add it to http://www.Solutions-Zone.com
***********************************************************

This message is sent to you because you are subscribed to
<imagepro-users@lists.mediacy.com>.
To unsubscribe, email to: <imagepro-users-off@lists.mediacy.com>
To switch to the DIGEST mode, email to
<imagepro-users-digest@lists.mediacy.com>
To switch to the INDEX mode, email to
<imagepro-users-index@lists.mediacy.com>
Send administrative queries to  <imagepro-users-request@lists.mediacy.com>
To subscribe or unsubscribe visit
http://www.solutions-zone.com/ipednld/subscriber.asp


***********************************************************
Need an Image-Pro macro or driver? Find it at http://www.Solutions-Zone.com
Got an Image-Pro macro or driver? Add it to http://www.Solutions-Zone.com
***********************************************************

This message is sent to you because you are subscribed to <imagepro-users@lists.mediacy.com>.
To unsubscribe, email to: <imagepro-users-off@lists.mediacy.com>
To switch to the DIGEST mode, email to <imagepro-users-digest@lists.mediacy.com>
To switch to the INDEX mode, email to <imagepro-users-index@lists.mediacy.com>
Send administrative queries to  <imagepro-users-request@lists.mediacy.com>
To subscribe or unsubscribe visit http://www.solutions-zone.com/ipednld/subscriber.asp



Search this Archive