I write dll on c #

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace TextToMDB { public class TextToMDB { private static bool chekComa(string arg) { if (arg.IndexOf(",")>0) { return false; } else { return true; } } [ComVisible(true)] public static void RemoveTab() { string text = File.ReadAllText(@"c:\Мои документы\333.txt"); if ( chekComa(text)) { text = text.Replace("\t",","); File.WriteAllText(@"c:\Мои документы\333.txt", text); } } } 

}

add link in aktsess

plus add enter image description here

but I cannot get to the method from the vba code, when I access RemoveTab I get a message

can't find dll entry point

  • one
    I don’t know if c # is able to export functions as useful, if you can, then you need to deliver more attributes (flags). The attribute ComVisible says that you will use the function through ActiveX, i.e. by means of set myObj = CreateObject("Ваш класс") and myObj.RemoveTab and in this way it is impossible. The class must be additionally registered in the system (rules of published COM objects). - nick_n_a
  • Try adding the attribute [System.Reflection.Obfuscation (Feature = "DllExport")] (taken from jonxxx.me/13-metatrader/… ) - nick_n_a
  • Here is a step by step guide on how to make exported com. How to call is written above. codeproject.com/Articles/12673/… - nick_n_a
  • And why these two procedures cannot be written on vba? First Instr function msdn.microsoft.com/ru-ru/library/47d6yh63.aspx Second CreateObject ("Scripting.FileSystemObject"), OpenTextFile ReadAll, etc. script-coding.com/WSH/FileSystemObject.html - nick_n_a

1 answer 1

I will give an example of one procedure for requests for c ++ and you can translate another procedure. It translates but with it a little more hassle. If you have set out the whole task, I suggest you rewrite it all to C ++. In the first procedure, you need to "guess the argument" - this is the only catch. It can be wchar_t* , VARIANT* , VARIANT . Most likely the first.

  extern "C" _export bool chekComa(wchar_t* arg); // в некоторых языках лучше добавить для "простого" имени. _export bool chekComa(wchar_t* arg) { while (*arg!=0) if (*arg++ == ',') return true; return false; } 

At your request, the second procedure will also be translated to c ++. The second option, why don't you write everything on VBA?

  function chekComa(string arg) as Bool Begin if instr(arg,",") = 0 then begin chekComa = false end else begin chekComa = true end end function sub RemoveTab() dim fso, f, d set fso = CreateObject("Scripting.FileSystemObject") set f = fso.OpenTextFile("c:\Мои документы\333.txt") d = f.ReadAll d = Replace(d, chr(8), ",") f.Close set f = fso.OpenTextFile("c:\Мои документы\333.txt",2) f.Write(d) f.Close end sub 

Wrote without checking in the code may be inaccurate.