StoneCodeMonkey
Well-known member
- Joined
- Apr 17, 2009
- Messages
- 56
- Programming Experience
- 5-10
Hello,
I am just starting my first project that will need COM Interoperabilty and I am looking for some guidance. But first, a little background on what I am trying to achieve. I have a Trumpf VectorMark laser at work that runs an application called Quickflow. Basically it is a graphical editor that produces a flow diagram of a program that the equipment uses to run.
In the Quickflow application, one of the intructions allows you to point to a DLL or EXE file and call on a function or method. It allows you to pass arguments to the DLL/EXE and also accepts values back. The system already has a file called tool_dll.dll which has many useful functions.
The help directory also included a file called tool_dll.h which contains definitions for the functions that can be called on. Sample below.
So, I figured I could use VB 2008 to create my own dll and add some functions that I need for management of the equipment.
I created a new project to test my theory. Code as follows, real simple to start with.
I built my project and then opened up VB6, created a new project and set a reference to the new DLL. A couple of lines of code to test with ....
The result was S100790001 exactly as expected. Pretty proud of myself at this point even though it was short lived.
I took my new DLL to the laser equipment (which has a Windows XP pc), saved it to the local HD, ran regasm which did not produce any errors.
At this point I launched the Quickflow editor, added and instruction to access the DLL, and ran the program. Which only resulted in the application throwing an error saying it couldn't open the file.
After scratching my head for a few minutes I had to accept the fact that I just didn't have a clue what was wrong or what to do next. I am really confused as to why the VB6 app so readily worked while the Quickflow program which accepts a file path to the DLL and a Name for the function to be called did not.
If anyone has any recommendations on what to try next I would greatly appreciate it.
Best regards,
I am just starting my first project that will need COM Interoperabilty and I am looking for some guidance. But first, a little background on what I am trying to achieve. I have a Trumpf VectorMark laser at work that runs an application called Quickflow. Basically it is a graphical editor that produces a flow diagram of a program that the equipment uses to run.
In the Quickflow application, one of the intructions allows you to point to a DLL or EXE file and call on a function or method. It allows you to pass arguments to the DLL/EXE and also accepts values back. The system already has a file called tool_dll.dll which has many useful functions.
The help directory also included a file called tool_dll.h which contains definitions for the functions that can be called on. Sample below.
VB.NET:
#ifndef TOOL_DLL_H
#define TOOL_DLL_H
#if defined (BUILD_DLL)
#define DLL_EXP __declspec(dllexport)
#else
#if defined (BUILD_APP)
#define DLL_EXP __declspec(dllimport)
#else
#define DLL_EXP
#endif
#endif
/**
* -----------------------------------------------------------------------------
* Description: Calculates the MODULO10 check-character from the
* given string ("data_in")
* Require: None
* Restriction: None
*
* @param data_in Pointer to a buffer with the given string
* @param data_out Pointer to a buffer with the MODULO10 check-character
* -----------------------------------------------------------------------------
*/
extern "C" DLL_EXP void MODULO10(char* data_in, char *data_out);
/**
* -----------------------------------------------------------------------------
* Description: Writes the given string ("data_in") to a log file with the
* following name "c:\\QuickFlow\\Log\\YY_MM_DD_HH_LOG_H1.TXT". If
* the file doesn't exist a new one will be created.
* Tokens:
* > YY = Year (04 for 2004)
* > MM = Month of year (01 to 12)
* > DD = Day of month (01 to 31)
* > HH = Hour of day (01 to 24)
* Require: Directory "c:\\QuickFlow\\Log" must exist
* Restriction: Every hour a new log file will be created.
*
* @param data_in Pointer to a buffer with the log text
* @param data_out Not used
* -----------------------------------------------------------------------------
*/
extern "C" DLL_EXP void WRITE_LOGFILE_H1(char* data_in, char *data_out);
/**
* -----------------------------------------------------------------------------
* Description: Writes the given string ("data_in") to a log file with the
* following name "c:\\QuickFlow\\Log\\YY_MM_DD_HH_LOG_H2.TXT". If
* the file doesn't exist a new one will be created.
* Tokens:
* > YY = Year (04 for 2004)
* > MM = Month of year (01 to 12)
* > DD = Day of month (01 to 31)
* > HH = Hour of day (01 to 24)
* Require: Directory "c:\\QuickFlow\\Log" must exist
* Restriction: Every hour a new log file will be created
*
* @param data_in Pointer to a buffer with the log text
* @param data_out Not used
* -----------------------------------------------------------------------------
*/
So, I figured I could use VB 2008 to create my own dll and add some functions that I need for management of the equipment.
I created a new project to test my theory. Code as follows, real simple to start with.
VB.NET:
<ComClass(Trumpf.ClassId, Trumpf.InterfaceId, Trumpf.EventsId)> _
Public Class Trumpf
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "e33c9f27-7f97-4ce8-9f75-2c07c31e8de4"
Public Const InterfaceId As String = "f5f48cf1-5a41-477b-9b0c-899aacfbd51b"
Public Const EventsId As String = "17656d74-7b4a-453d-aeb4-8a8126583508"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
Public Function GetSerialNumber() As String
Dim DateCode As String = Today.ToString("yy").PadLeft(2, "0") + Today.DayOfYear.ToString("000")
Return "S" + DateCode + 1.ToString("0000")
End Function
End Class
I built my project and then opened up VB6, created a new project and set a reference to the new DLL. A couple of lines of code to test with ....
VB.NET:
Option Explicit
Sub Main()
Dim t As New Trumpf.Trumpf
Debug.Print t.GetSerialNumber
End Sub
The result was S100790001 exactly as expected. Pretty proud of myself at this point even though it was short lived.
I took my new DLL to the laser equipment (which has a Windows XP pc), saved it to the local HD, ran regasm which did not produce any errors.
At this point I launched the Quickflow editor, added and instruction to access the DLL, and ran the program. Which only resulted in the application throwing an error saying it couldn't open the file.
After scratching my head for a few minutes I had to accept the fact that I just didn't have a clue what was wrong or what to do next. I am really confused as to why the VB6 app so readily worked while the Quickflow program which accepts a file path to the DLL and a Name for the function to be called did not.
If anyone has any recommendations on what to try next I would greatly appreciate it.
Best regards,