Search code examples
c#.netvisual-foxpro

c# dll in vfp, Unable to use


I have written my code in c#, and build dll. When I m creating object in vfp, Im getting error.

I am using below code in vfp

SET LIBRARY TO bt_print.tlb
hh=CREATEOBJECT("bt_print.bt")

My c# code is

I have checked "Register for COM interop" check box.

Please correct me , what i am doing wrong.

Thanks in advance.


Solution

  • Checkmark the "Make the Assembly COM-Visible" - Project Settings, Application Page, Assembly Information.

    In C#, add the ClassInterface and ProgId.

    using System;
    using System.Runtime.InteropServices;
    
    namespace bt_print
    
    {
        [ClassInterface(ClassInterfaceType.AutoDual)]
        [ProgId("bt_print.bt")]
        public class bt
        {
            public void search_bt()
            {
            }
    
            public void sendfile(String fl)
            {
            }
        }
    }
    

    In VFP, use the NEWOBJECT() function.

    hh = NEWOBJECT("bt_print.bt")