0
votes

I am trying to program a DLL in C#. This DLL should work as a kind of port for Selenium to Visual FoxPro 9 SP2. My goal is to make a DLL (or other libray type) that will work with VFP and can use Selenium. So I searched a lot (all weekend) and I found nothing. For clarification, I found a lot of help, but none of it worked at all. I got to a point, where with regasm I managed to create .reg and .tlb files and run .reg file to create registry entry, but in VFP and function CreateObejct() [acording to some tutorials it's the only way to use .NET DLLs in VFP] it gave error "Entry point for function HelloWorld was not found" (or something similar to that, you got the idea) and same with DECLARE, which worked but function cannot be ran 'cos some issues (don't remeber excatly, something like "Class definiton cannot be found" or "Function defenition cannot be found" or "File cannot be found"). I tried everything that I found. I mainly tried to follow this tutorial: https://www.tek-tips.com/viewthread.cfm?qid=1619542 but I used a lot of other sources.

I tried:

  1. Registering it using regsv32 (not working with C#) and with regasm (worked but in VFP gave error)
  2. Before registering use sn -k and then call regasm with it (not worked at all)
  3. Changing all settings that I found I should change (even in combinations)
  4. Building with all types of kinds of build settings (I think it should be x86 as 32-bit, register as COM interop = true)
  5. Combining all above

I actually have no code, 'cos I am trying to make at least working DLL with HelloWordl() and Add() functions.

Thank you for any help

Edit: I am going to add here some code, that I already tried:

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface INarexDLL
{
    [DispId(0)]
    int Add(int a, int b);
    [DispId(1)]
    string HelloWorld();
}

[ComSourceInterfaces(typeof(INarexDLL))]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("Narex.NarexDLL")]
[ComVisible(true)]
public class Class1 : INarexDLL
{
    public int Add(int a, int b)
    {
        return a + b;
    }
    public string HelloWorld()
    {
        return "Hello world";
    }
}

And:

/// <summary>
/// Narex dll.
/// </summary>
[ComVisible(true)]
[Guid("82fb954d-378c-4e3e-9d57-2f812da564bc")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface INarexDLL
{
    /// <summary>
    /// Hellos the world.
    /// </summary>
    /// <returns>Hello World</returns>
    string HelloWorld();
    /// <summary>
    /// Add the specified a and b.
    /// </summary>
    /// <returns>a + b</returns>
    /// <param name="a">First number</param>
    /// <param name="b">Second number</param>
    int Add(int a, int b);
}

/// <summary>
/// Narex dll.
/// </summary>
[ComVisible(true)]
[Guid("bf99a6f7-4a0b-4896-813b-dbea3f75041a")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("NarexV4.NarexDLL")]
public class NarexDLL : INarexDLL
{
    /// <summary>
    /// Hellos the world.
    /// </summary>
    /// <returns>Hello World</returns>
    public string HelloWorld()
    {
        return "Hello World from C# COM DLL";
    }

    /// <summary>
    /// Add the specified a and b.
    /// </summary>
    /// <returns>a + b </returns>
    /// <param name="a">First number</param>
    /// <param name="b">Second number</param>
    public int Add(int a, int b)
    {
        return a + b; 
    }
}
2
Just an opinion: seems like learning .NET and ditching FoxPro would be easier than what you are trying to do here.pcalkins

2 Answers

0
votes

Have a look at West Wind dotnetbridge (wwdotnetbridge) This provides robust access to net classes

0
votes

(would not fit to a comment)

Looks like you don't know VFP. You might start by learning it, or as of today skip learning it and continue with C# or one of the other languages selenium has support.

VFP can use 2 types of DLL.

  • Win32 DLL. This is the one you meant with DECLARE. I don't think the DLL you have written in C# is a win32 DLL. These can be written in C++ and even if you want, compiled as FLL for VFP's native usage.

  • Activex (COM) DLL. These are the ones that we write and use in VFP using C#. For it to be usable by VFP, you must register for COM Interop. In simple terms, you create a new class library project, be sure you are targeting x86 (VFP is 32 bits), and register for COM interop.

A sample looks like:

//...
using System.Threading.Tasks;

namespace SbcHelper
{
    [ComSourceInterfaces(typeof(IcbSBCEvents))]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ProgId("cbNetCOM.cbSBCx")]
    [ComVisible(true)]
    public class cbSBCWorker
    {
        #region Bulk Info
        public delegate void delFeedbackProgress(SbcState state, string tableName, string message, double percentComplete);
        public event delFeedbackProgress Feedbackprogress;
        private List<BulkInfo> bulkInfo = new List<BulkInfo>();
        private List<SbcMessage> messages;

        public cbSBCWorker()
        { // ... 

and would be instantiated from VFP:

oSomething = CreateObject("cbNetCOM.cbSBCx")

For registration on another computer you need to sign it and you could either do that with sn.exe (sn -k ...) or in your project settings. Registration is NOT done using regsvr32 but regasm:

regasm yourLib.dll /codebase

You might also try using .Net libraries from VFP. If you go for it check this link:

Kodnet