When I use C# callback function in VBA it shows "entry point not found " -
i want use c# callback function in vba. when call c# function shows "entry point not found "
how can fix it? thanks
ps:i checked make assembly com-visible , register com inter environment:ms office excel 2007, ms visual studio 2008
vba code:
declare function result lib"c:\users\admin\desktop\myprog\new_dll_test\new_dll_test\bin\debug\new_dll_test.dll" alias "msg" (byval p long) integer function disp() msgbox x end function sub addresult(byval p long) dim x long x = result(p) debug.print x end sub sub testnow_click() call addresult(addressof disp) end sub
c# code:
using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.interopservices; namespace new_dll_test { [guid("f1286974-0f1a-466c-8389-dd1ab7e3eed2"), interfacetype(cominterfacetype.interfaceisdual)] interface msginterface { int msg; } public unsafe class msgprocess { public int msg(int* p) { return add(p,1); } public int add(int* p, int j) { return j+1; } } }
a vba declare function allows access stdcall function exported dll. com visible class , interface different thing. although 2 methods can work together, function acting unmanaged export can return com visible object. or each method can used independently of other.
calling static c# functions vba
if want write vba code way, , access dll need create unmanaged export c# project. believe there 2 ways this. 1 manually create wrapper in managed c++ exports function. other use compile-time build task , library unmanagedexports.
using com visible c# object vba
to use c# class through com interop need register c# assembly using regasm.exe create object in vba using createobject function. both class , interface need com visible. you can find basic tutorial here.
Comments
Post a Comment