vb.netdll函数 vb 函数

VB .NET 制作的DLL无法被 .NET 程序引用你没加namespace , 加一个命名空间
namespace xxx
{
//your code
}
最好用VS工程里的添加引用直接选中这个dll,然后程序里写namespace 就可以访问其中的内容了 。
右键点击你的工程名称,选添加引用,选浏览 , 找到你的dll,确定 。
让后在你的代码里上面协商using 你的命名空间,就可以放心使用了 。
还可以用System.Reflection Assembly.LoadFrom动态加载一个dll也可以 。
vb.net 调用CDLL,传递动态数组微软给出的例子
C#的例子
我有互操作的书籍,你需要的话,可以给我百度消息,发给你!
你试试下面这个 , 我记得不是很清楚了,shared不行就用auto
DllImport(\"XXX.dll\")
Private Shared Function GetDataArray (ByRef_Array As long, ByVal len As Integer) As Boolean
你试试看吧,家里没有环境,有问题明天给你看吧
vb.net中使用C中带LPCTSTR参数的DLL的问题vb.netdll函数你也太牛逼了!!!你不用MFC,你要用WINDOWS API吧,,,你想不用API连SQL???
吐血,累死你啊!!
好,,给你个C链接SQL2000vb.netdll函数的例子!
/*这是一个程序,只使用C就可以连接数据库,你编译后要按程序要求配置一下环境也许才可以使用*/
/**************************************************
*操作系统WindowsXPProfessionalSP2
*开发环境VisualStudio.NET2003
*数据库SQLServer2000
*注释配置环境,可以参考代码中的ConnectionString赋值部分
*另外对于SQLSERVER的密码和用户名得修改一下程序的用户名和密码
*这个程序用的是SQLSERVER的默认例子数据库,除了用户名和密码 , 代码基本不用怎么改
*你多注意一下你的环境比如ODBC呀 , 数据库的用户名呀,口令呀 , 还有
*操作系统,数据库,程序,三方面的配合吧 。
**************************************************/
//BeingConnectionStringCpp
#import"C:\ProgramFiles\CommonFiles\System\ADO\msado15.dll"\
no_namespacerename("EOF","EndOfFile")
#includeole2.h
#includestdio.h
#includeconio.h
//Functiondeclarations
inlinevoidTESTHR(HRESULTx);
voidConnectionStringX();
_bstr_tGetState(intintState);
voidPrintProviderError(_ConnectionPtrpConnection);
voidPrintComError(_com_errore);
///////////////////////////////////////////////////////////
////
//MainFunction//
////
///////////////////////////////////////////////////////////
voidmain()
{
if(FAILED(::CoInitialize(NULL)))
return;
ConnectionStringX();
//Waithereforusertoseetheoutput..
printf("\nPressanykeytocontinue...");
getch();
::CoUninitialize();
}
///////////////////////////////////////////////////////////
////
//ConnectionStringXFunction//
////
///////////////////////////////////////////////////////////
voidConnectionStringX()
{
//DefineConnectionobjectpointers.
//Initializepointersondefine.
//TheseareintheADODB::namespace
_ConnectionPtrpConnection1=NULL;
_ConnectionPtrpConnection2=NULL;
_ConnectionPtrpConnection3=NULL;
_ConnectionPtrpConnection4=NULL;
//DefineOtherVariables
HRESULThr=S_OK;
try
{
//OpenaconnectionusingOLEDBsyntax.
TESTHR(pConnection1.CreateInstance(__uuidof(Connection)));
pConnection1-ConnectionString=
"Provider='sqloledb';DataSource='MySqlServer';"
"InitialCatalog='Pubs';IntegratedSecurity='SSPI';";
pConnection1-ConnectionTimeout=30;
pConnection1-Open("","","",adConnectUnspecified);
printf("cnn1state:%s\n",
(LPCTSTR)GetState(pConnection1-State));
//OpenaconnectionusingaDSNandODBCtags.
//ItisassumedthatyouhavecreateDSN'Pubs'withausernameas
//'MyUserId'andpasswordas'MyPassword'.
【vb.netdll函数 vb 函数】TESTHR(pConnection2.CreateInstance(__uuidof(Connection)));
pConnection2-ConnectionString="DSN=Pubs;UID=MyUserId;PWD=MyPassword;";
pConnection2-Open("","","",adConnectUnspecified);
printf("cnn2state:%s\n",
(LPCTSTR)GetState(pConnection2-State));
//OpenaconnectionusingaDSNandOLEDBtags.
TESTHR(pConnection3.CreateInstance(__uuidof(Connection)));
pConnection3-ConnectionString="DataSource=Pubs;";
pConnection3-Open("","","",adConnectUnspecified);
printf("cnn3state:%s\n",
(LPCTSTR)GetState(pConnection3-State));
//OpenaconnectionusingaDSNandindividual
//argumentsinsteadofaconnectionstring.
//ItisassumedthatyouhavecreateDSN'Pubs'withausernameas
//'MyUserId'andpasswordas'MyPassword'.
TESTHR(pConnection4.CreateInstance(__uuidof(Connection)));
pConnection4-Open("Pubs","MyUserId","MyPassword",adConnectUnspecified);
printf("cnn4state:%s\n",
(LPCTSTR)GetState(pConnection4-State));
}
catch(_com_errore)
{
//Notifyuserofanyerrors.
//PassaconnectionpointeraccessedfromtheConnection.
PrintProviderError(pConnection1);
if(pConnection2)
PrintProviderError(pConnection2);
if(pConnection3)
PrintProviderError(pConnection3);
if(pConnection4)
PrintProviderError(pConnection4);
PrintComError(e);
}
//Cleanupobjectsbeforeexit.
if(pConnection1)
if(pConnection1-State==adStateOpen)
pConnection1-Close();
if(pConnection2)
if(pConnection2-State==adStateOpen)
pConnection2-Close();
if(pConnection3)
if(pConnection3-State==adStateOpen)
pConnection3-Close();
if(pConnection4)
if(pConnection4-State==adStateOpen)
pConnection4-Close();
}
///////////////////////////////////////////////////////////
////
//GetStateFunction//
////
///////////////////////////////////////////////////////////
_bstr_tGetState(intintState)
{
_bstr_tstrState;
switch(intState)
{
caseadStateClosed:
strState="adStateClosed";
break;
caseadStateOpen:
strState="adStateOpen";
break;
default:
;
}
returnstrState;
}
///////////////////////////////////////////////////////////
////
//PrintProviderErrorFunction//
////
///////////////////////////////////////////////////////////
voidPrintProviderError(_ConnectionPtrpConnection)
{
//PrintProviderErrorsfromConnectionobject.
//pErrisarecordobjectintheConnection'sErrorcollection.
ErrorPtrpErr=NULL;
if((pConnection-Errors-Count)0)
{
longnCount=pConnection-Errors-Count;
//Collectionrangesfrom0tonCount-1.
for(longi=0;inCount;i)
{
pErr=pConnection-Errors-GetItem(i);
printf("Errornumber:%x\t%s\n",pErr-Number,
(LPCSTR)pErr-Description);
}
}
}
///////////////////////////////////////////////////////////
////
//PrintComErrorFunction//
////
///////////////////////////////////////////////////////////
voidPrintComError(_com_errore)
{
_bstr_tbstrSource(e.Source());
_bstr_tbstrDescription(e.Description());
//PrintComerrors.
printf("Error\n");
printf("\tCode=lx\n",e.Error());
printf("\tCodemeaning=%s\n",e.ErrorMessage());
printf("\tSource=%s\n",(LPCSTR)bstrSource);
printf("\tDescription=%s\n",(LPCSTR)bstrDescription);
}
//EndConnectionStringCpp
VB.net调用Matlab生成的DLL问题已测试vb.netdll函数,源码如下:
一、Matlab函数代码
function x = LU5(a, b)
for i = 1 : length(a)
x(i) = a(i)b(i);
end
二、VB.NET 2005 测试代码
Private Sub test()
Dim st As New QCS_com.QCS_LU5
Dim a() As Double = {1, 2, 3, 4}
Dim b() As Double = {1, 2, 3, 4}
Dim x As New Object
st.lu5(1, x, a, b)
Dim r As Double(,)
r = CType(x, Double(,))
End Sub
三、测试截图见附图
补充一下环境:Matlab6.5 版本vb.netdll函数,是基于COM调用的 。最新版的.net调用没试验过 。这个是vb.netdll函数我前一阵子帮同学写的,他装的版本是6.5 , 所以就装vb.netdll函数了个6.5的版本,后来因为涉及到小波及拟合 , 用COM打包调用有些问题,最后还是采用vb.netdll函数了引擎方式进行处理了 。
vb如何实现调用c#.net写的一个dll,这个dll里面都是些类,不是函数,想用vb把里面的类调用出来,求帮忙!按照vb.netdll函数我的理解vb.netdll函数,vb.netdll函数你的这个需求是没有办法做到的,除非C#的dll被封装为了一个COM组件并且注册了,但是你的这个dll已经写成了 , 所以理论上来说应该不是com,而C#的程序集是不提供向前兼容的,所以用一个老的语言调用新的技术的组件是做不到的,不过也有一种可能性 , 不过很难实现,大体逻辑这样,首先通过vb调用一个native的组件,用C或者c完成,在这个组件里面加载clr,在clr里面加载c#的程序集,实例化对象,执行调用
vb.net调用两个不同的dll , 里面都有一个相同的模块名,冲突了 。怎么办其中一个在其他类或模块中申明,直接新建一个类也可以 。
public class 函数
代码
end class
vb.netdll函数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb 函数、vb.netdll函数的信息别忘了在本站进行查找喔 。

    推荐阅读