Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DllExport class
Message
From
17/11/2016 02:34:59
 
General information
Forum:
ASP.NET
Category:
Other
Title:
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01643554
Message ID:
01643585
Views:
30
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi everybody,
>>>
>>>I need to create a library project what we should be able to use from VFP project and C# project (and, potentially although unlikely from C++).
>>>
>>>There is another solution here by another developer - quite complex for me. I'm trying to use it as a prototype for my project.
>>>
>>>That solution consists of many projects. One of them has the following file in the project
>>>
>>>
>>>using System;
>>>using System.Collections.Generic;
>>>using System.Text;
>>>using System.Runtime.CompilerServices;
>>>using System.Runtime.InteropServices;
>>>
>>>namespace DllExport
>>>{
>>>    /// <summary>
>>>    /// Attribute added to a static C# method to export it
>>>    /// </summary>
>>>    [AttributeUsage(AttributeTargets.Method)]
>>>    public class DllExportAttribute : Attribute
>>>    {
>>>        private string m_exportName;
>>>        private CallingConvention m_callingConvention;
>>>
>>>        /// <summary>
>>>        /// Constructor 1
>>>        /// </summary>
>>>        /// <param name="exportName"></param>
>>>        public DllExportAttribute(string exportName)
>>>            : this(exportName, System.Runtime.InteropServices.CallingConvention.StdCall)
>>>        {
>>>        }
>>>
>>>        /// <summary>
>>>        /// Constructor 2
>>>        /// </summary>
>>>        /// <param name="exportName"></param>
>>>        /// <param name="callingConvention"></param>
>>>        public DllExportAttribute(string exportName, CallingConvention callingConvention)
>>>        {
>>>            m_exportName = exportName;
>>>            m_callingConvention = callingConvention;
>>>        }
>>>
>>>        /// <summary>
>>>        /// Get the export name, or null to use the method name
>>>        /// </summary>
>>>        public string ExportName
>>>        {
>>>            get { return m_exportName; }
>>>        }
>>>
>>>        /// <summary>
>>>        /// Get the calling convention
>>>        /// </summary>
>>>        public string CallingConvention
>>>        {
>>>            get
>>>            {
>>>                switch (m_callingConvention)
>>>                {
>>>                    case System.Runtime.InteropServices.CallingConvention.Cdecl:
>>>                        return typeof(CallConvCdecl).FullName;
>>>
>>>                    case System.Runtime.InteropServices.CallingConvention.FastCall:
>>>                        return typeof(CallConvFastcall).FullName;
>>>
>>>                    case System.Runtime.InteropServices.CallingConvention.StdCall:
>>>                        return typeof(CallConvStdcall).FullName;
>>>
>>>                    case System.Runtime.InteropServices.CallingConvention.ThisCall:
>>>                        return typeof(CallConvThiscall).FullName;
>>>
>>>                    case System.Runtime.InteropServices.CallingConvention.Winapi:
>>>                        return typeof(CallConvStdcall).FullName;
>>>
>>>                    default:
>>>                        return "";
>>>                }
>>>            }
>>>        }
>>>    }
>>>}
>>>
>>>and the other class in that project uses that attribute this way
>>>
>>>
>>>[DllExport("Test", System.Runtime.InteropServices.CallingConvention.StdCall)]
>>>        public static String Test(String dataSource, String initialCatalog)
>>>        {
>>>            return dataSource + ' ' + initialCatalog;
>>>        }
>>>
>>>that class is static and all methods and properties are static too for that class.
>>>
>>>Do I need to follow the same in my new project and add that attribute class as well?
>>
>>Wouldn't have thought so. Just create a dll, make methods and properties that should be visible to vfp public in the usual way and set the 'Register for Com Interop' flag in the build settings.
>>
>
>Assuming I just made a public class with several public methods and registered it for Com interop, how would I call it from VFP?
>
>Do I need to register it using regsvr32 ?

Use regasm.

>
>
>>>
>>>The VFP calls are
>>>
>>>
>>>declare integer InitializeConnection in "Siriusware.Fingerprint.Netlink x86.dll" string, string
>>>					lnInitializeCode = InitializeConnection(.cODBC_DSN, .cDatabase)
>>>
>>>Just want to understand if this is needed in my case too?
>>>
>>>My class is supposed to use HttpClient class and use its post and get methods to communicate with external API. I found this sample
>>>
>>>https://www.dotnetperls.com/httpclient
>>>
>>>is it how I generally should do it?
>>
>>You might have a problem handling async calls if the results are to be consumed by VFP ?.
>
>Yes, may be?
>
>Also, I am reading the technical design document prepared by my colleague, he suggests to use that other project as a prototype and expose functions exactly the same way as in the other project.
>
>May be I can just add my new project inside that solution? It already has lots of tests solutions and some other good (and very complex things) written by my colleague.
>
>I started a new DLL project using VS template but it added nothing for me, so I would have to build that project practically from scratch and I am feeling a bit intimidated as I am not sure from where to start.

Just create a class with the public properties and methods that you wish to be exposed over COM.
If your colleagues existing code uses functionality that will be useful you could reference that DLL in your project and make calls to it from there rather then modifying or adding to his code directly ?
If his code contains async calls then I think your wrapper would need to wait for the result before returning it to VFP (unless there is some trick I'm not aware of).
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform