Solved

adding a dll to SL project

Posted on 2011-03-13
49
865 Views
Last Modified: 2012-06-21
Hi Experts

I am trying to add a dll to the SL project and i get the message "you cant add a reference to DLL as it was not built against the silverlight runtime. Silverlight projects will only work with silverlight assemblies"

What can i do to get this to add?

Thanks
0
Comment
Question by:razza_b
  • 27
  • 22
49 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35123517
What type of DLL are you working with?  That message does say what it means...you need add a Silverlight DLL to the Silverlight project.  It might be possible to wrap the DLL calls into a Silverlight assembly, but that would require knowing what type of DLL you are trying to reference.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35123557
Hi thelearnedone its a tformer dll for printing. How could I wrap it in a SL dll?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35123570
We really need to find out what type of DLL that is, to determine how best to handle this question.  If it is an ActiveX, you are going to need to do something special.  If it is a C-type library, you might be able to use p/invoke to access the DLL methods.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35126840
I'll find out let you know.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35130815
what i got in reply from the third party...

We have already a wrapper, but not for the Silverlight CLR. The TECIT.TFORMer.dll assembly is based upon the standard .NET runtime and not upon Silverlight. This .NET assembly acts as a .NET wrapper for the TFORMer60 DLL (which is C/C++ based and no COM/ActiveX). The only COM/ActiveX based DLL is the TFORMer60COM.dll, which is not required in your case.

>>wrap it in a SL DLL or to use p/invoke to access your TFormer DLL methods

You are thinking of writing a Silverlight wrapper for the TFORMer60.dll for which I have no experience until now. If it is possible to include natively (e.g. WIN32 or WIN64) compiled DLLs into a Silverlight App (XAP file) - you could try it. As said, I have no experience with that (and if it is supported by Silverlight) but we would assist you by providing the DLL declaration file (header file) we have developed for our .NET wrapper ¿ See attachment. You cannot simply take this file and use/compile it in your app, but you can check out the parameter declaration of the DLL API functions, which in fact saves a lot of time if you create your own wrapper. Please omit our custom EntryPointUnix /CharSetUnix parameters.

I hope this can help you.


TFormerDll.cs
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35132231
You should be able to take that wrapper, and add it to a Silverlight Class Library, and then add a reference to that from the Silverlight client application.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35132665
How do you had it to a SL class library?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35132970
1) Create a new Silverlight Class Library from the File | New | Project | C# | Silverlight | Silverlight Class Library template.

2) Add a new class for TFormerDllFactory.

    Paste in the class text:

public class TFormerDllFactory
  {
    const string TFormerDllPathUnix       = "libTFORMer6.so";

#if DEBUG
    const string TFormerDllPathWindows    = "TFormer60D.dll";
    const string TFormerDllx64PathWindows = "TFormer60x64D.dll";
#else
    const string TFormerDllPathWindows    = "TFormer60.dll";
    const string TFormerDllx64PathWindows = "TFormer60x64.dll";
#endif
    
    // see "Multithreaded Singleton " http://msdn.microsoft.com/en-us/library/ms998558.aspx
    private static volatile TFormerDll instance = null;
    private static String sLockInstance = "";

    /// <summary>
    /// Create an object implementing the TFormerDll interface either from the windows Dll or
    /// the Linux shared library.
    /// </summary>
    public static TFormerDll Instance()
    {
        if (instance == null)
        {
            lock (sLockInstance)
            {
                if (instance == null)
                {
                    LibLoader loader = new LibLoader(typeof(TFormerDll), TFormerDllPathWindows, TFormerDllx64PathWindows, TFormerDllPathUnix);
                    instance = (TFormerDll)loader.Load();
                }
            }
        }

        return instance;
    }

  }

Open in new window


3) Add a interface file for TFormerDll interface, and paste the text:

public interface TFormerDll
  {
    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   IntPtr TFormer_Init(IntPtr hRepository);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_Exit(IntPtr pInstance);

    [DllImportPortable( EntryPoint = "TFormer_SetConfigFileW", CharSet = CharSet.Unicode, 
                        EntryPointUnix = "TFormer_SetConfigFile", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetConfigFile(IntPtr pInstance, string pszFileName);

    [DllImportPortable( EntryPoint = "TFormer_SetRepositoryNameW", CharSet = CharSet.Unicode, 
                        EntryPointUnix = "TFormer_SetRepositoryName", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetRepositoryName(IntPtr pInstance, string pszFileName);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetPrinterType(IntPtr pInstance, PrinterType ePrinterType);

    [DllImportPortable( EntryPoint = "TFormer_SetPrinterNameW", CharSet = CharSet.Unicode, 
                        EntryPointUnix = "TFormer_SetPrinterName", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetPrinterName(IntPtr pInstance, string pszPrinterName, IntPtr pDevMode);

    [DllImportPortable(EntryPoint = "TFormer_SetJobTrayControlNameW", CharSet = CharSet.Unicode, 
                       EntryPointUnix = "TFormer_SetJobTrayControlName", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetJobTrayControlName(IntPtr pInstance, string pszSettingsName);

    [DllImportPortable( EntryPoint = "TFormer_SetProjectNameW", CharSet = CharSet.Unicode, 
                        EntryPointUnix = "TFormer_SetProjectName", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetProjectName(IntPtr pInstance, string pszProjectName);

    [DllImportPortable(EntryPoint = "TFormer_SetFormNameW", CharSet = CharSet.Unicode, 
                       EntryPointUnix = "TFormer_SetFormName", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetFormName(IntPtr pInstance, string pszFormName);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_ResetData(IntPtr pInstance);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_NewRecord(IntPtr pInstance);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetRecordCopy(IntPtr pInstance, uint nRecordCopy);

    [DllImportPortable(EntryPoint = "TFormer_SetVarValueW", CharSet = CharSet.Unicode, 
                       EntryPointUnix = "TFormer_SetVarValue", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetVarValue(IntPtr pInstance, string szVarName, string szVarValue);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetReuseValues (IntPtr pInstance, bool bClear);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetHandleEscapeSequences(IntPtr pInstance, bool bHandleEsc);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetNumberOfCopies(IntPtr pInstance, int nCopies);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetStartRowColumn(IntPtr pInstance, int nStartCol, int nStartRow);

    [DllImportPortable(EntryPoint = "TFormer_SetOutputNameW", CharSet = CharSet.Unicode, 
                       EntryPointUnix = "TFormer_SetOutputName", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetOutputName(IntPtr pInstance, string pszOutputName);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetPageFromTo(IntPtr pInstance, uint nPageFrom, uint nPageTo);

    [DllImportPortable( EntryPoint     = "TFormer_LicenseW",    CharSet = CharSet.Unicode, 
                        EntryPointUnix = "TFormer_License",     CharSetUnix = CharSet.Auto)]
     unsafe   void TFormer_License(string pszLicensee, uint dwKind, int nLicenses, string pszLicenseKey);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   bool TFormer_IsDesignerAvailable();

    [DllImportPortable(EntryPoint = "TFormer_OpenDesignerW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_OpenDesigner", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_OpenDesigner(IntPtr pInstance, string pszDesignExe, bool bShowSplash, bool bMaximize, bool bUseExistingInstance, string pszExtraParameters);

    [DllImportPortable(EntryPoint = "TFormer_SetImportFieldForRecordCopyW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_SetImportFieldForRecordCopy", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetImportFieldForRecordCopy(IntPtr pInstance, string pszFieldName, bool bIsAttribute);

    [DllImportPortable(EntryPoint = "TFormer_SetTxtDataFileW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_SetTxtDataFile", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetTxtDataFile(IntPtr pInstance, string pszFileName, char cSeparator, char cTextQualifier);

    [DllImportPortable(EntryPoint = "TFormer_SetODBCDataW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_SetODBCData", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetODBCData(IntPtr pInstance, string pszDSN, string pszUser, string pszPwd, string pszSQLSelect);

    [DllImportPortable(EntryPoint = "TFormer_SetXmlDataFileW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_SetXmlDataFile", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetXmlDataFile(IntPtr pInstance, string pszFileName);

    [DllImportPortable( EntryPoint = "TFormer_SetXmlDataFileExW", CharSet = CharSet.Unicode,
                        EntryPointUnix = "TFormer_SetXmlDataFileEx", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SetXmlDataFileEx(IntPtr pInstance, string pszFileName, string pszXsltFileName, string pszXsltTFC);

    [DllImportPortable(EntryPoint = "TFormer_SetDatasourceNameW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_SetDatasourceName", CharSetUnix = CharSet.Auto)]
    unsafe    int TFormer_SetDatasourceName(IntPtr pInstance, string pszDatasourceName);

    [DllImportPortable(EntryPoint = "TFormer_SetDSParameterValueW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_SetDSParameterValue", CharSetUnix = CharSet.Auto)]
    unsafe    int TFormer_SetDSParameterValue(IntPtr pInstance, string pszParameterName, string pszValue);

    [DllImportPortable(EntryPoint = "TFormer_SaveXmlW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_SaveXml", CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_SaveXml(IntPtr pInstance, string pszFileName);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TFormer_Print(IntPtr pInstance);

    [DllImportPortable( EntryPoint = "TFormer_GetLastErrorDescriptionW", CharSet = CharSet.Unicode,
                        EntryPointUnix = "TFormer_GetLastErrorDescription", CharSetUnix = CharSet.Auto)]
     unsafe   IntPtr TFormer_GetLastErrorDescription(IntPtr pInstance);

    [DllImportPortable(EntryPoint = "TFormer_GetLastErrorInformationW", CharSet = CharSet.Unicode, 
                       EntryPointUnix = "TFormer_GetLastErrorInformation", CharSetUnix = CharSet.Auto)]
     unsafe   IntPtr TFormer_GetLastErrorInformation(IntPtr pInstance);

    [DllImportPortable(EntryPoint = "TFormer_GetLastErrorSourceW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_GetLastErrorSource", CharSetUnix = CharSet.Auto)]
     unsafe   IntPtr TFormer_GetLastErrorSource(IntPtr pInstance);


    [DllImportPortable(EntryPoint = "TFormer_GetVarUsageW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TFormer_GetVarUsage", CharSetUnix = CharSet.Auto)]
     unsafe   DataFieldUsage TFormer_GetVarUsage(IntPtr pInstance, string pszVarName, out int peCode);

      /* TECZip Methods */

    [DllImportPortable(EntryPoint = "TecUnzipper_AllocW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TecUnzipper_Alloc", CharSetUnix = CharSet.Auto)]
     unsafe   IntPtr TecUnzipper_Alloc(string pszFileName );

    [DllImportPortable(EntryPoint = "TecUnzipper_ExtractW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TecUnzipper_Extract", CharSetUnix = CharSet.Auto)]
     unsafe   int TecUnzipper_Extract( IntPtr hZip, string pszDirectory );

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TecUnzipper_GetFileCount( IntPtr hZip );

    [DllImportPortable(EntryPoint = "TecUnzipper_GetFileW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TecUnzipper_GetFile", CharSetUnix = CharSet.Auto)]
     unsafe   IntPtr TecUnzipper_GetFile( IntPtr hZip, int index );

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TecUnzipper_DeleteAllFiles( IntPtr hZip );

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   void TecUnzipper_Free( IntPtr hZip );

    [DllImportPortable(EntryPoint = "TecUnzipper_FindFileByExtW", CharSet = CharSet.Unicode,
                       EntryPointUnix = "TecUnzipper_FindFileByExt", CharSetUnix = CharSet.Auto)]
     unsafe   int TecUnzipper_FindFileByExt(IntPtr hZip, string pszExtension, int startIndex, bool caseInsensitive);

    [DllImportPortable(CharSet = CharSet.Ansi, CharSetUnix = CharSet.Auto)]
     unsafe   int TecUnzipper_Base64Decode(IntPtr hZip );

    [DllImportPortable( EntryPoint = "TecUnzipper_GetFilenameW", CharSet = CharSet.Unicode,
                        EntryPointUnix = "TecUnzipper_GetFilename", CharSetUnix = CharSet.Auto)]
     unsafe   IntPtr TecUnzipper_GetFilename( IntPtr hZip );
  }

Open in new window


0
 
LVL 1

Author Comment

by:razza_b
ID: 35136493
Thanks, I've created those 2 files and in the TFormerDllFactory classs the libloader nees a namespce which im not sure what it uses?

As for the TFormerDll class the DllImportPortable, PrinterType and DataFieldUsage need a namespace also.

Is this something i need from TEC-IT or something i can add as a namspace to make these become available?

0
 
LVL 1

Author Comment

by:razza_b
ID: 35136762
Got in touch again with TEC-IT this is what their saying...

You cannot simply take this file and use/compile it in your app, but you can check out the parameter declaration of the DLL API functions. The lib loader class is a third party software / class we use (maybe open source), you won’t need it. The DLLImportPortable is our implementation for cross platform library import, you won’t need it.

I suggest to start with an empty class, use the standard DLLImport attribute as shown here:

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute(v=vs.71).aspx
http://msdn.microsoft.com/en-us/library/26thfadc(v=vs.71).aspx

Example:

    [DllImport (CharSet = CharSet.Ansi]
     unsafe   IntPtr TFormer_Init(IntPtr hRepository);

This should be sufficient. For a normal printing application you won’t need the whole API.

The PrinterType is a normal enumeration (0, 1, 2, 3…), the base type should be LONG data type. Please check out the developer reference (installed with TFORMer SDK Setup) for details.

The same with DataFieldUsage, also enum.

First of all, I would make a pilot project, which calls only TFORMer Init and Deinit in the DLL - only to see if the TFORMer DLL can be loaded and accessed in the Silverlight environment (on a clean system!!!). You need the TFORMer Runtime files on your system. Either the client installs the TFORMer SDK setup on his system - or you distribute all TFORMer Runtime files within your XAP file (for details see the developer manual, section Distribution/Deployment).
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35139556
That sounds like great advice.  Do the instructions make sense?
0
 
LVL 1

Author Comment

by:razza_b
ID: 35140309
Not in the slightest. I did ask if they can just create the class for me rather than going through the hassle of doing what he said, but not replied, does it sound easy to you?

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35140357
I described some steps before, for the TFormerDllFactory class and the TFormerDll interface.  What they are saying is that you need to change the DllImportPortable attribute to just DllImport for all the declarations.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35140500
You need to find out what PrinterType is in this line this:

unsafe int TFormer_SetPrinterType(IntPtr pInstance, PrinterType ePrinterType);

Open in new window


and DataFieldUsage is in this line:

unsafe DataFieldUsage TFormer_GetVarUsage(IntPtr pInstance, string pszVarName, out int peCode);

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35140546
You also need to find out how to use those calls defined, like TFormer_Init, TFormer_SetConfigFile, etc.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35141054
will get back to asap. Thanks
0
 
LVL 1

Author Comment

by:razza_b
ID: 35141107
Got this back in reply...

I would like to help- but I have no ready to use C# class, except our internal wrapper class, which is for multi-platform and not suitable. To make a new one, I would need developer resources and time (not available, we are committed to a project right now, sorry).

In order to help you:

The attached C sample (PDF) shows the minimum API functions (highlighted blue, underlined) you need in your wrapper class.

Start with defining TFORMer Init (on page 2)

hTForm = TFormer_Init (NULL);
if (hTForm )
{

If you have questions to a specific API function, please let me know(TEC-IT).

sample-basic-api-functions--2-.pdf
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35141799
Here is my take on this question.

1) Create a class for the p/invoke declares (TFormerDll.cs):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Printing
{

    internal class TFormerDll
    {

        internal enum PrinterType
        {
            Standard,
        }

        internal enum DataFieldUsage
        {
            Standard,
        }

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe IntPtr TFormer_Init(IntPtr hRepository);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_Exit(IntPtr pInstance);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetConfigFileW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetConfigFile(IntPtr pInstance, string pszFileName);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetRepositoryNameW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetRepositoryName(IntPtr pInstance, string pszFileName);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_SetPrinterType(IntPtr pInstance, PrinterType ePrinterType);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetPrinterNameW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetPrinterName(IntPtr pInstance, string pszPrinterName, IntPtr pDevMode);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetJobTrayControlNameW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetJobTrayControlName(IntPtr pInstance, string pszSettingsName);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetProjectNameW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetProjectName(IntPtr pInstance, string pszProjectName);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetFormNameW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetFormName(IntPtr pInstance, string pszFormName);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_ResetData(IntPtr pInstance);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_NewRecord(IntPtr pInstance);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_SetRecordCopy(IntPtr pInstance, uint nRecordCopy);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetVarValueW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetVarValue(IntPtr pInstance, string szVarName, string szVarValue);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_SetReuseValues(IntPtr pInstance, bool bClear);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_SetHandleEscapeSequences(IntPtr pInstance, bool bHandleEsc);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_SetNumberOfCopies(IntPtr pInstance, int nCopies);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_SetStartRowColumn(IntPtr pInstance, int nStartCol, int nStartRow);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetOutputNameW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetOutputName(IntPtr pInstance, string pszOutputName);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_SetPageFromTo(IntPtr pInstance, uint nPageFrom, uint nPageTo);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_LicenseW", CharSet = CharSet.Unicode)]
        internal unsafe void TFormer_License(string pszLicensee, uint dwKind, int nLicenses, string pszLicenseKey);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe bool TFormer_IsDesignerAvailable();

        [DllImport("TFormer.dll", EntryPoint = "TFormer_OpenDesignerW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_OpenDesigner(IntPtr pInstance, string pszDesignExe, bool bShowSplash, bool bMaximize, bool bUseExistingInstance, string pszExtraParameters);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetImportFieldForRecordCopyW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetImportFieldForRecordCopy(IntPtr pInstance, string pszFieldName, bool bIsAttribute);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetTxtDataFileW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetTxtDataFile(IntPtr pInstance, string pszFileName, char cSeparator, char cTextQualifier);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetODBCDataW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetODBCData(IntPtr pInstance, string pszDSN, string pszUser, string pszPwd, string pszSQLSelect);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetXmlDataFileW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetXmlDataFile(IntPtr pInstance, string pszFileName);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetXmlDataFileExW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetXmlDataFileEx(IntPtr pInstance, string pszFileName, string pszXsltFileName, string pszXsltTFC);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetDatasourceNameW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetDatasourceName(IntPtr pInstance, string pszDatasourceName);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SetDSParameterValueW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SetDSParameterValue(IntPtr pInstance, string pszParameterName, string pszValue);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_SaveXmlW", CharSet = CharSet.Unicode)]
        internal unsafe int TFormer_SaveXml(IntPtr pInstance, string pszFileName);

        [DllImport("TFormer.dll", CharSet = CharSet.Ansi)]
        internal unsafe int TFormer_Print(IntPtr pInstance);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_GetLastErrorDescriptionW", CharSet = CharSet.Unicode)]
        internal unsafe IntPtr TFormer_GetLastErrorDescription(IntPtr pInstance);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_GetLastErrorInformationW", CharSet = CharSet.Unicode)]
        internal unsafe IntPtr TFormer_GetLastErrorInformation(IntPtr pInstance);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_GetLastErrorSourceW", CharSet = CharSet.Unicode)]
        internal unsafe IntPtr TFormer_GetLastErrorSource(IntPtr pInstance);

        [DllImport("TFormer.dll", EntryPoint = "TFormer_GetVarUsageW", CharSet = CharSet.Unicode)]
        internal unsafe DataFieldUsage TFormer_GetVarUsage(IntPtr pInstance, string pszVarName, out int peCode);
    }
}

Open in new window


2) Create a Factory class to generate a singleton instance of the worker class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using My.WeatherService;

namespace Printing
{
    public class TFormerDllFactory
    {

        private static volatile TFormerService instance = null;
        private static string lockInstance = "";

        /// <summary>
        /// Create an object implementing the TFormerDll interface from the windows Dll
        /// </summary>
        public static TFormerService Instance()
        {
            if (instance == null)
            {
                lock (lockInstance)
                {
                    if (instance == null)
                    {
                        instance = new TFormerService();
                    }
                }
            }

            return instance;
        }

    }
}

Open in new window


3) Create a service class, which is a facade layer for the DLL:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using My.WeatherService;

namespace Printing
{

    internal class TFormerService
    {

        public static void PrintArticles(PrintArgs arguments, List<Article> articleList)
        {
            TFormerDll library = new TFormerDll();

            // Initialize the library
            IntPtr handle = library.TFormer_Init(IntPtr.Zero);

            if (handle != IntPtr.Zero)
            {
                library.TFormer_SetRepositoryName(handle, arguments.FileName);

                library.TFormer_SetProjectName(handle, arguments.ProjectName);

                library.TFormer_SetNumberOfCopies(handle, arguments.Copies);

                foreach (Article article in articleList)
                {
                    library.TFormer_NewRecord(handle); /* add first data record */
                    library.TFormer_SetVarValue(handle, "ArticleNo", article.Number);
                    library.TFormer_SetVarValue(handle, "ArticleName", article.Name);
                    library.TFormer_SetVarValue(handle, "ArticlePrice", article.Price);
                }

                library.TFormer_ResetData(handle);
                library.TFormer_SetTxtDataFile(handle, arguments.DataFile, ',', '\"');
                library.TFormer_Print(handle);
                library.TFormer_Exit(handle);
            }
        }
    }

    internal class PrintArgs
    {
        public string FileName { get; set; }
        public string ProjectName { get; set; }
        public int Copies { get; set; }
        public string DataFile { get; set; }
    }

     internal class Article
    {
         public string Number { get; set; }
         public string Name { get; set; }
         public string Price { get; set; }
    }
}

Open in new window


4) PrintArgs defines the arguments for the printing, which can change without breaking the interface to the print methods (PrintArticles in this example).

5) Article is a definition class to simplify the example code taken from the .pdf file.



0
 
LVL 1

Author Comment

by:razza_b
ID: 35142103
Will take a look 2moro thanks for all your help :-)
0
 
LVL 1

Author Comment

by:razza_b
ID: 35146564
Hi TheLearnedOne

TFormerDll class (no errors), TFormerDllFactory (no errors), TFormerService just a couple of errors...

errors - PrintArgs & List<Article>  namespace cannot be found
public static void PrintArticles(PrintArgs arguments, List<Article> articleList)

warning - library  unreachable code detected
library.TFormer_NewRecord(handle); /* add first data record */
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35148256
Those were only meant to be examples of how to achieve what you need, with what you have.  I would imagine that you would ultimately be doing something different for the printing.  That warning is because the class in the for loop is unrecognized.  I would start thinking about how you want to take that example code, and make it what you need.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35150332
OK i'll see what i can do, but i'm not sure exactly what i'm going to use, TFormer themselves would know best since they developed it, I've sent on the code you supplied to them to see if they can help out modify what i need, i'll be in touch soon to see what the outcome is, you've been a great help!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35150407
I thought of something that you might want to think about.

Naming Convention for Unmanaged Code Methods
http://msdn.microsoft.com/en-us/library/btadwd4w(v=VS.100).aspx

.NET Framework 2.0 Security Guidelines - Unmanaged Code
http://www.guidanceshare.com/wiki/.NET_Framework_2.0_Security_Guidelines_-_Unmanaged_Code

Rename TFormerDll to UnsafeNativeMethods, since the methods are all marked as unsafe.

0
 
LVL 1

Author Comment

by:razza_b
ID: 35150628
Got some feedback dont think they are willing to help write thier own code, but see attached.
TFormer-feedback.docx
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 35150722
Those comments make sense:

1) Don't worry about Article class, just come up with something similar, if that's what you need.

2) Put TFormer_Exit in a finally block

3) Change TFormer.dll to TFormer60.dll in the DllImport attributes.  You could use a constant string value:

private const string TFormer = "TFormer60.dll";

4) PrintArgs and Article were private classes defined at the end of the class module that I included:

internal class PrintArgs
    {
        public string FileName { get; set; }
        public string ProjectName { get; set; }
        public int Copies { get; set; }
        public string DataFile { get; set; }
    }

     internal class Article
    {
         public string Number { get; set; }
         public string Name { get; set; }
         public string Price { get; set; }
    }

Open in new window



0
 
LVL 1

Author Comment

by:razza_b
ID: 35154966
Does this look ok to you?

see attached.
latest-TFormer-code-for-SL.docx
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 35155135
OK, I was a little hasty before, so I made some tweaks:

1) Don't catch an exception in a DLL, let the caller catch the exception (try/finally).

2) Change to UnsafeNativeMethods, since the CLR does a little magic when you name the classes SafeNativeMethods, UnsafeNativeMethods, etc.  

3) Define a version-specific DLL name in a constant, so you only need to change one place.

4) If you continue to use PrintArgs, rename to PrintArgument (no abbreviations, no plural is Extreme Programming).  I only added enough properties for this example code, but that doesn't cover the full need of what I imagine that the TFormer DLL supports.

5) Added TODO for things that need more information.

6) Changed UnsafeNativeMethods to internal unsafe extern static, so that you don't need to create an instance to call the methods.

namespace Printing
{
    public class TFormerService
    {
        public static void PrintArticles(PrintArgument arguments, Article[] articleList)
        {
            // Initialize the library
            IntPtr handle = UnsafeNativeMethods.Init(IntPtr.Zero);
            try
            {
                if (handle != IntPtr.Zero)
                {
                    UnsafeNativeMethods.SetRepositoryName(handle, arguments.FileName);

                    UnsafeNativeMethods.SetProjectName(handle, arguments.ProjectName);

                    UnsafeNativeMethods.SetNumberOfCopies(handle, arguments.Copies);

                    foreach (Article article in articleList)
                    {
                        UnsafeNativeMethods.NewRecord(handle);
                        UnsafeNativeMethods.SetVarValue(handle, "ArticleNo", article.Number);
                        UnsafeNativeMethods.SetVarValue(handle, "ArticleName", article.Name);
                        UnsafeNativeMethods.SetVarValue(handle, "ArticlePrice", article.Price);
                    }

                    UnsafeNativeMethods.ResetData(handle);
                    UnsafeNativeMethods.SetTxtDataFile(handle, arguments.DataFile, ',', '\"');
                    UnsafeNativeMethods.Print(handle);
                    
                }
            }
            finally
            {
                if (handle != IntPtr.Zero)
                {
                    UnsafeNativeMethods.Exit(handle);
                }
            }
        }
    }  
}

namespace Printing
{

    internal class UnsafeNativeMethods
    {

        // TODO:  Find out what these values are for SetPrinterType
        internal enum PrinterType
        {
            Standard,
        }

        // TODO:  Find out what these values are for GetVarUsage
        internal enum DataFieldUsage
        {
            Standard,
        }

        // If the DLL changes, there is one place to change the version string.
        private const string TFORMER = "TFormer60.dll";

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static IntPtr Init(IntPtr hRepository);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int Exit(IntPtr pInstance);

        [DllImport(TFORMER, EntryPoint = "SetConfigFileW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetConfigFile(IntPtr pInstance, string pszFileName);

        [DllImport(TFORMER, EntryPoint = "SetRepositoryNameW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetRepositoryName(IntPtr pInstance, string pszFileName);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int SetPrinterType(IntPtr pInstance, PrinterType ePrinterType);

        [DllImport(TFORMER, EntryPoint = "SetPrinterNameW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetPrinterName(IntPtr pInstance, string pszPrinterName, IntPtr pDevMode);

        [DllImport(TFORMER, EntryPoint = "SetJobTrayControlNameW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetJobTrayControlName(IntPtr pInstance, string pszSettingsName);

        [DllImport(TFORMER, EntryPoint = "SetProjectNameW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetProjectName(IntPtr pInstance, string pszProjectName);

        [DllImport(TFORMER, EntryPoint = "SetFormNameW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetFormName(IntPtr pInstance, string pszFormName);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int ResetData(IntPtr pInstance);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int NewRecord(IntPtr pInstance);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int SetRecordCopy(IntPtr pInstance, uint nRecordCopy);

        [DllImport(TFORMER, EntryPoint = "SetVarValueW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetVarValue(IntPtr pInstance, string szVarName, string szVarValue);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int SetReuseValues(IntPtr pInstance, bool bClear);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int SetHandleEscapeSequences(IntPtr pInstance, bool bHandleEsc);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int SetNumberOfCopies(IntPtr pInstance, int nCopies);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int SetStartRowColumn(IntPtr pInstance, int nStartCol, int nStartRow);

        [DllImport(TFORMER, EntryPoint = "SetOutputNameW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetOutputName(IntPtr pInstance, string pszOutputName);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int SetPageFromTo(IntPtr pInstance, uint nPageFrom, uint nPageTo);

        [DllImport(TFORMER, EntryPoint = "LicenseW", CharSet = CharSet.Unicode)]
        internal unsafe extern static void License(string pszLicensee, uint dwKind, int nLicenses, string pszLicenseKey);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static bool IsDesignerAvailable();

        [DllImport(TFORMER, EntryPoint = "OpenDesignerW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int OpenDesigner(IntPtr pInstance, string pszDesignExe, bool bShowSplash, bool bMaximize, bool bUseExistingInstance, string pszExtraParameters);

        [DllImport(TFORMER, EntryPoint = "SetImportFieldForRecordCopyW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetImportFieldForRecordCopy(IntPtr pInstance, string pszFieldName, bool bIsAttribute);

        [DllImport(TFORMER, EntryPoint = "SetTxtDataFileW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetTxtDataFile(IntPtr pInstance, string pszFileName, char cSeparator, char cTextQualifier);

        [DllImport(TFORMER, EntryPoint = "SetODBCDataW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetODBCData(IntPtr pInstance, string pszDSN, string pszUser, string pszPwd, string pszSQLSelect);

        [DllImport(TFORMER, EntryPoint = "SetXmlDataFileW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetXmlDataFile(IntPtr pInstance, string pszFileName);

        [DllImport(TFORMER, EntryPoint = "SetXmlDataFileExW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetXmlDataFileEx(IntPtr pInstance, string pszFileName, string pszXsltFileName, string pszXsltTFC);

        [DllImport(TFORMER, EntryPoint = "SetDatasourceNameW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetDatasourceName(IntPtr pInstance, string pszDatasourceName);

        [DllImport(TFORMER, EntryPoint = "SetDSParameterValueW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SetDSParameterValue(IntPtr pInstance, string pszParameterName, string pszValue);

        [DllImport(TFORMER, EntryPoint = "SaveXmlW", CharSet = CharSet.Unicode)]
        internal unsafe extern static int SaveXml(IntPtr pInstance, string pszFileName);

        [DllImport(TFORMER, CharSet = CharSet.Ansi)]
        internal unsafe extern static int Print(IntPtr pInstance);

        [DllImport(TFORMER, EntryPoint = "GetLastErrorDescriptionW", CharSet = CharSet.Unicode)]
        internal unsafe extern static IntPtr GetLastErrorDescription(IntPtr pInstance);

        [DllImport(TFORMER, EntryPoint = "GetLastErrorInformationW", CharSet = CharSet.Unicode)]
        internal unsafe extern static IntPtr GetLastErrorInformation(IntPtr pInstance);

        [DllImport(TFORMER, EntryPoint = "GetLastErrorSourceW", CharSet = CharSet.Unicode)]
        internal unsafe extern static IntPtr GetLastErrorSource(IntPtr pInstance);

        [DllImport(TFORMER, EntryPoint = "GetVarUsageW", CharSet = CharSet.Unicode)]
        internal unsafe extern static DataFieldUsage GetVarUsage(IntPtr pInstance, string pszVarName, out int peCode);
    }
}

namespace Printing
{
    public class PrintArgument
    {
        public string FileName { get; set; }
        public string ProjectName { get; set; }
        public int Copies { get; set; }
        public string DataFile { get; set; }
    }
}

namespace Printing
{
    public class Article
    {
        public string Number { get; set; }
        public string Name { get; set; }
        public string Price { get; set; }
    }
}

Open in new window

0
 
LVL 1

Author Comment

by:razza_b
ID: 35158105
Latest feedback....

The code looks good.

    public enum PrinterType
    {
        Default = 0,
        Win32 = 1,
        Repository = 2,
        Cups = 3,
        PostscriptFile = 4,
        HtmlFile = 5,
        PdfFile = 6,
        PostscriptPrinter = 7,
        TextPrinter = 8,
        TextFile = 9,
        ePrinterType_ImageBmp = 10,
        ePrinterType_ImageGif = 11,
        ePrinterType_ImageJpg = 12,
        ePrinterType_ImagePcx = 13,
        ePrinterType_ImagePng = 14,
        ePrinterType_ImageTga = 15,
        ePrinterType_ImageTifSingle = 16,
        ePrinterType_ImageTifMultiPage = 17,
        ePrinterType_ZPLPrinter = 18,
        ePrinterType_ZPLFile = 19,
        Invalid = 20,
    }

    public enum DataFieldUsage
    {
        NotUsed = 0,
        Normal = 1,
        Calculated = 2,
        Parameter = 3,
        Invalid = 4,
    }

Note for compiling: Since the TFORMer60.DLL is native 32 bit DLL (x86 platform) you should not specify ANY as target (can lead to errors on 64 bit systems) - instead use target x86  (32 bit).
0
 
LVL 1

Author Comment

by:razza_b
ID: 35158245
oh when i just built the project i get errors!!

The PrintArticles in the TFormerService class...
Inconsistent accessibility: parameter type 'Printing.Article[]' is less accessible than method 'Printing.TFormerService.PrintArticles(Printing.PrintArgs, Printing.Article[])'

and the UnsafeNativeMethods class for every internal unsafe extern static int i.e. Init, Exit, SetConfigFile...
Unsafe code may only appear if compiling with /unsafe
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35161516
Oops, I failed to mention that I changed the scope for the classes to public, since I got the same compile errors.  You need to open the project properties, and switch to the Build tab, and check the "Allow unsafe code".
Snapshot.png
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35161526
The Build tab, also has the "Platform target" above the "Allow unsafe code" check box (x86 in my example).
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35161546
public class:

namespace Printing
{
    public class PrintArgument
    {
        public string FileName { get; set; }
        public string ProjectName { get; set; }
        public int Copies { get; set; }
        public string DataFile { get; set; }
    }
}

namespace Printing
{
    public class Article
    {
        public string Number { get; set; }
        public string Name { get; set; }
        public string Price { get; set; }
    }
}

Open in new window

0
 
LVL 1

Author Comment

by:razza_b
ID: 35164258
No worries.

See my screenshot i dont have an option to select from any cpu and the checkbox is disabled.
build-props.docx
0
 
LVL 1

Author Comment

by:razza_b
ID: 35164276
TEC-IT also mentioned i should include all the DLL's/licence/files including the TFormer60.dll....

All of these…

¿¿TFormerRep60.dll
¿¿TECBaseU.dll
¿¿TFTBarCode9.dll
¿¿freetype238MT.dll
¿¿freetype.LICENSE
¿¿iconv.dll
¿¿libxml2.dll
¿¿libxml2.LICENSE
¿¿libxslt.dll
¿¿zlib1.dll
¿¿zlib.README
¿¿TFORMer.xml

But that would also mean doing what we have just done with this one? or can we be able to include them in the reference folder?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35164436
You need to determine what type of DLLs those are, and then we can determine how to reference them.  If they are .NET assemblies, then you can easily add them as a reference.  If they are C/C++ DLLs, then you would need to know their exports, and use the same approach that you used with the TFormer60.dll.

You can try to remove the "unsafe" from all the p/invoke signatures, to see if the compiler error goes away.

What version of Silverlight are you using?  I found an MSDN magazine article that talks about security model in Silverlight 2:

Security In Silverlight 2
http://msdn.microsoft.com/en-us/magazine/cc765416.aspx

I would need to know the Silverlight version, so that we can explore if there are any differences to the security model for that specific version.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35164473
Im using SL 4.

I'll look through link and get onto TEC-IT about dll's.

Thanks!!
0
 
LVL 1

Author Comment

by:razza_b
ID: 35164502
I removed all unsafe cleaned/rebuilt and ne error!!
0
 
LVL 1

Author Comment

by:razza_b
ID: 35165344
All of the DLLs + XML file are required and loaded by the TFORMer DLL. They are C/C++ DLLs and you don’t need to call any function inside of them.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35169537
If the DLL makes the call to the licensing, then I would assume that they just need to be in the same folder as the TFormer60.dll.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35169547
Here is some reading material about Silverlight 4 security model:

Silverlight Application Security Model
http://msdn.microsoft.com/en-us/library/dd470128(v=vs.95).aspx
0
 
LVL 1

Author Comment

by:razza_b
ID: 35179291
Hi TheLearnedOne

Yes true they all need to be in the same folder as TFormer60.dll, I dont have to create anymore classes.

From the TFormer SDK where i get the rest of the dll's am i just adding these as a reference in the SL class library?

Thanks

0
 
LVL 1

Author Comment

by:razza_b
ID: 35180019
If I used to use tformer code like this in my previous C#.net….

        string prj = "DELL";
        string frm = "Serial Label 61";
        string cfg = @"\\sr-agd-wipdev\packingLabels\";
        string lce = "SModTechnologies, Inc.";
        string lck = "A34AB63D4F7CAFD4069685920DDC9";
        string rep = @"\\sr-agd-wipdev\packingLabels\packing.tfr";

        TECIT.TFORMer.JobDataRecordSet JobRecSet = new TECIT.TFORMer.JobDataRecordSet();
        TECIT.TFORMer.Record Record = new TECIT.TFORMer.Record();
        TECIT.TFORMer.Job tfjob = new TECIT.TFORMer.Job();

        tfjob.RepositoryName = (string)rep;
        tfjob.ProjectName = (string)prj;
        tfjob.FormName = (string)frm;
        tfjob.JobData = JobRecSet;

        Record = new TECIT.TFORMer.Record();
        Record.Data.Add("SerialNumber", "TEST");
        Record.Data.Add("CustomerPartNumber", "TEST2");
        Record.Data.Add("CustomerRevision", "999");
        JobRecSet.Records.Add(Record);

        tfjob.PrinterName = @"PDF995 (redirected 2)";
        tfjob.ConfigFile = (string)cfg;
        tfjob.NumberOfCopies = 1;

     TECIT.TFORMer.TFORMer.License((string)lce, TECIT.TFORMer.LicenseKind.Developer, 2, (string)lck);
        try
        {
            tfjob.Print();
            SqlContext.Pipe.Send("PRINTS OK!!!");
        }
        catch (TECIT.TFORMer.TFORMerException ex)
        {
            throw new System.Exception(("Msg "
                            + (ex.Message + ("\n" + ("Info "
                            + (ex.Information + ("\n" + ("Source " + ex.Source))))))));
           
        }
        tfjob.Dispose();


How do I do this from the new code I’ve created? In my PrintArgs class I have these properties just now but how am I supposed to get record and recordset and license like above?

            string prj = "DELL";
            string frm = "Serial Label 61";
            string cfg = @"\\sr-agd-wipdev\packingLabels\";
            string lce = "SModTechnologies, Inc.";
            string lck = "A34AB63D4F7CAFD4069685920DDC9";
            string rep = @"\\sr-agd-wipdev\packingLabels\packing.tfr";

            Printing.PrintArgs pntObj = new Printing.PrintArgs();

            pntObj.ProjectName = (string)prj;
            pntObj.RepositoryName = (string)rep;
            pntObj.FormName = (string)frm;
            pntObj.PrinterName = @"PDF995 (redirected 2)";
            pntObj.ConfigFile = (string)cfg;
            pntObj.Copies = 1;

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35181214
Let's keep this in perspective:  you can only a reference to a .NET assembly, or a COM assembly (with a type library), and these DLLs are neither.

The PrintArgument (PrintArgs) class is used to define properties for things that need to be passed from the caller to the called method.  You can add members to the class, and use them in the print method, without breaking the interface.  If you look at how events are handled (with classes that derive from EventArgs), you can start to see the same pattern.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35181363
Ok so how will i reference these dll's without writing more code? TEC-IT say i dont need to write anymore code just reference them.



0
 
LVL 1

Author Comment

by:razza_b
ID: 35182168
I've came up with this but dont know if im on the right path?

string prj = "DELL";
            string frm = "Serial Label 61";
            string cfg = @"\\sr-agd-wipdev\packingLabels\";
            string lce = "SMod Technologies, Inc.";
            string lck = "A34AB63D4F7CAFD40E6969285920DDC9";
            string rep = @"\\sr-agd-wipdev\packingLabels\packing.tfr";
           
            Printing.UnsafeNativeMethods.SetRecordCopy();
            Printing.UnsafeNativeMethods.NewRecord();
            Printing.PrintArgs pntObj = new Printing.PrintArgs();

            pntObj.ProjectName = (string)prj;
            pntObj.RepositoryName = (string)rep;
            pntObj.FormName = (string)frm;
            pntObj.PrinterName = @"PDF995 (redirected 2)";
            pntObj.ConfigFile = (string)cfg;
            pntObj.Copies = 1;
           
            Printing.UnsafeNativeMethods.SetVarValue("SerialNumber", "TEST");
            Printing.UnsafeNativeMethods.SetVarValue("CustomerPartNumber", "TEST2");
            Printing.UnsafeNativeMethods.SetVarValue("CustomerRevision", "999");

            Printing.UnsafeNativeMethods.License((string)lce, 3, 2, (string)lck);
            try
            {
                Printing.UnsafeNativeMethods.Print();
            }
            catch (Exception ex)
            {
                throw new System.Exception(("Msg "
                                + (ex.Message + ("\n" + ("Info "
                                + (ex.InnerException + ("\n" + ("Source " + ex.Source))))))));

            }
            Printing.UnsafeNativeMethods.Exit();

When does the TFormerService class come into it to call the printArticles method?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35185580
Oh, my, this is starting to look like a never-ending question, and I am not always good about drawing the line.  This is starting to feel like a different, related question to me.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35187002
Yeah lets close this off i agree, but from that code i gave you do you think this is how it should be done?
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 500 total points
ID: 35189160
My last parting words are, "It looks good to me, but I can't really be 100% certain".  You just need to experiment, and see what works.  You might want to start outside of Silverlight, with either a Windows Forms or Console application, until you have a good feel for the managed TFormer wrapper.
0
 
LVL 1

Author Closing Comment

by:razza_b
ID: 35189381
No worries i appreciate all your help and you still deserve the points, its just down to me to try it and test it, but i can see the pattern that i need to follow.

Bt I'll try in a test app away from SL, good idea!!

Thanks again!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 5 115
C# Error - Add Failed 12 38
Showdialog 8 20
Calling stored proc in EDMX 11 19
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now