Llamar un DLL externo desde el COOL:PLEX

Obsydian, Cool:Plex, Advantage Plex, AllFusion Plex...

Moderadores: Jorge Ubeda, pacopicon

Llamar un DLL externo desde el COOL:PLEX

Notapor enripy » Mié Abr 14, 2010 4:44 pm

Hola..

Necesito llamar un DLL hecha por aplicaciones externas al Cool:plex, la cual reciba y devuelva parametros..

Desde ya muchas gracias
Enri
enripy
 
Mensajes: 1
Registrado: Mié Abr 14, 2010 4:17 pm

Re: Llamar un DLL externo desde el COOL:PLEX

Notapor Jorge Ubeda » Vie Abr 16, 2010 2:02 pm

enripy escribió:Hola..

Necesito llamar un DLL hecha por aplicaciones externas al Cool:plex, la cual reciba y devuelva parametros..

Desde ya muchas gracias
Enri


En el manual de Plex (User Guide), cap 9, (Integrating Plex applications with other systems):

Calling Prebuilt Windows DLLs
This topic details how you can call prebuilt Windows DLLs (Dynamic Link Libraries). These can be DLLs that have been supplied by third-parties, that you have hand-coded, or that you created with AllFusion Plex.

Calling pre-built AllFusion Plex DLLs has the following benefits:

You can link internal AllFusion Plex functions without having to rebuild them every time you create a new model. For example, the AllFusion Plex class libraries are supplied with prebuilt libraries of standard functions required by the pattern and class libraries.

You can share your compiled internal functions with other users.

For large models, it enables you to divide the internal functions into separate libraries in order to avoid limitations on the size of an individual library.
There are two main methods for calling prebuilt DLLs:

Linking in the required functions during the build process. For this method, you need the .H and .LIB files for the DLL concerned.

Loading the DLL explicitly at runtime. This method requires additional coding in your source code to load and unload the DLL into and out of memory.
The remainder of this topic describes the first of these techniques.

Note: In order for a prebuilt DLL to call an AllFusion Plex function, the prebuilt function itself must be called by an AllFusion Plex function. However, note that you can use OLE Automation to call AllFusion Plex DLLs from third-party applications. See What is AllFusion Plex's OLE Automation?.

Linking in Prebuilt Libraries
To call a function from a DLL you need:

The .DLL, .OBJ or .LIB file containing the function

A header (.H) file containing the function prototypes

Creating the Import Library (.LIB) File
If you do not already have an import library, you need to create one so that the build process recognizes the function names and avoids unresolved external errors.

Creating a Library of Internal AllFusion Plex Functions
For functions created in AllFusion Plex, the .LIB file is created when you generate and build the internal functions. The .LIB file takes the same name as the local model and is created in the target directory for C++ builds. To create a library:

Create a new local model with a suitable name (for example, MYLIB.MDL).

Generate and build the required internal functions.
The library (MYLIB.LIB in this example) is created in the C++ target directory. By following the instructions in Specifying the .LIB and .H files you can now use this library whenever you need to build functions that call the internal functions it contains.

Creating a Library for Third-Party or Hand-Coded Functions
For 32-bit hand-coded functions, you can automatically create a .LIB file by specifying the \IMPLIB option on the LINK command.

For 32-bit third-party functions, if the .DLL did not ship with an import library, and you cannot use run-time dynamic linking to access the .DLL, see "How to Create 32-bit Import Libraries without .OBJs or Source" in the Microsoft Visual C++ Knowledge Base.
Specifying the .LIB and .H Files
In the C++ Build section of the Generate and Build Options dialog, specify the name of the import library (.LIB) file. Separate multiple .LIB names by a semi-colon (with no space). You can also fully qualify each library with a path name (for example, C:\TESTING\MYLIB.LIB). No path is necessary if the .LIB files are placed in the AllFusion Plex Lib sub-directory.

Note: There is no documented limit for library names you can specify for the compiler.

Also, in the C++ Build section, specify the directories in which the .H files are located. Separate multiple entries by a semi-colon. You do need to specify this information in order to call pre-built AllFusion Plex functions (in this case, the generated .H files are not required, only the .LIB file).

Note: If the .H files are in the path or in the generation directory, you do not need to specify the header directory.

Ensure the Use Pre-Built Libraries option is selected.

Writing the Source Code
These steps are not required for AllFusion Plex-created functions.

In your model, create a source code object to contain the code that calls the external function.

Enter the required source code, remembering to insert a #include statement for the header file.
Note: The #include statement is generated into the beginning of function's header (.H) file, and not into its CPP file. If multiple API source code objects contain the same #include statement, only one line is generated.

For example:

#include "calldll.h" // Include DLL function prototypes
{
char szOutResult[32]; // Output params
long OutZ = 0L; // are buffered
// through C datatypes
CallMe(&(1), &(2), &(3), &OutZ, szOutResult);
// Now pass back output params
&(4) = OutZ;
&(5) = szOutResult;
}

Note: AllFusion Plex parameters cannot be cast directly to C++ data types. Instead a buffering mechanism is required.

Use the API Call statement in your action diagrams to call the source code.

Examples in this Topic
The preceding example is taken from a sample model called CALLEXT.MDL which is available in the AllFusion Plex SAMPLES directory. This model contains an AllFusion Plex function that calls a C++ function in a hand-coded DLL (called CALLDLL.DLL). The C++ function takes input parameters from the AllFusion Plex function, performs a calculation - the results of which display in a message box - and then returns two parameters to the AllFusion Plex function.

CALLDLL.DLL and the required .H and .LIB files are already installed in the SAMPLES\GEN directory.

To build the function in the sample model:

Open the Generate and Build window and generate the function.

Build the function using the Create Exe command.
Note: If you use the Build command to build the function, it fails at runtime (because CALLDLL.DLL cannot be located).


Espero que te sirva
Jorge Ubeda
Site Admin
 
Mensajes: 229
Registrado: Mié Oct 26, 2005 6:00 pm
Ubicación: Valencia

Usando OLE

Notapor Jorge Ubeda » Vie Abr 16, 2010 2:06 pm

El segundo método, que se puede leer en el mismo capítulo. Aquí va un caso simple. La explicación es mucho más detallada:
Objects and Methods
You create AllFusion Plex Functions by first creating an App object. The App object has a Function method that allows the OLE Automation client to access an AllFusion Plex function.

The Visual Basic example located in the Plex\Samples\obole folder, demonstrates how to create the AllFusion Plex OLE App Object and then get a Function object from the App object.

Creating an AllFusion Plex OLE App Object
'--------------------------------------------------'
'1. Create the AllFusion Plex application object'
'--------------------------------------------------'
Set ObApp = CreateObject ("ObRunOLE450RS.App")
'--------------------------------------------------'
'2. Create the AllFusion Plex functions that you want to call'
'--------------------------------------------------'
'Create a Category.Get Sequential Proxy'
FncFileNme = "AA2JF"
FncImplNme = "AA2JF"
Set Category_GetSequential = ObApp.Function(FncFileNme, FncImplNme)

Create the App Object using the correct class name. See ObRun and OLE Class Name Table.

Ask the App object for the Function that you are interested in calling.
You can fully qualify the function name of the function, or you can rely on the normal function search mechanisms to load the function. The Function method of the App object requires the function's DLL file name and the function's implementation name.

Call the Function that was instantiated by the App object by invoking the "Call" method for that Function object.

Create and initialize the parameters for the Function before making the function call.


En resúmen...es posible, pero hay que leer el manual...;-)
Jorge Ubeda
Site Admin
 
Mensajes: 229
Registrado: Mié Oct 26, 2005 6:00 pm
Ubicación: Valencia

Llamada a una DLL externa desde Plex

Notapor Eduardo » Mar May 31, 2011 8:44 am

Hola a todos,
vuelvo con este tema aunque ha pasado un año desde que se creó, ya que tengo el mismo problema:
Tengo que llamar a una dll hecha en otro lenguage (creo que C#) de la que solo tengo la dll y la estructura de los métodos existentes.

Al mirar la ayuda de Plex, solo informa de realizarlo mediante el primer metodo (en la compilación ) y por tanto para funciones Plex o realizadas en C++.

El 2º metodo del que habla: Cargar la DLL de forma explicita en tiempo de ejecución, que es el que me interesa no informa absolutamente nada y no he encontrado donde mirar.
Entiendo que la 2ª parte del tema (mediante automatización OLE) y desde mi desconocimiento - solo he visto los ejemplos - se utilizaría para llamar funciones Plex desde otros entornos VB,...

Si alguien ha hecho algo parecido le estaría muy agradecido de que me informara de como hacerlo, ya que hace unos años me toco hacer lo mismo con otra DLL esta vez escrita en Delphi y despues de muchas pruebas sin resultado, la única forma en la que logre conectarme a ella fue realizando un OCX en VB que llamase a la DLL (esto si es sencillo) y entonces desde Plex insertar el OCX creado en un panel y con VB script llamar a este último. Como solución de último recurso está bien, pero claro lo ideal sería no tener que meter todo eso y lograrlo con script de C++ directamente.

Sin más, muchas gracias por vuestra atención (y perdón por la chapa)
Eduardo
 
Mensajes: 3
Registrado: Jue May 12, 2011 1:16 pm
Ubicación: Vitoria


Volver a Plex

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 3 invitados

cron