Option Explicit On
創(chuàng)新互聯(lián)公司致力于網(wǎng)站建設,網(wǎng)站制作設計,營銷網(wǎng)頁按需定制開發(fā),外貿(mào)營銷網(wǎng)站建設,企業(yè)網(wǎng)站建設,微信平臺小程序開發(fā),網(wǎng)站SEO優(yōu)化,網(wǎng)站設計制作案例豐富,是成都做網(wǎng)站公司和建站公司,歡迎咨詢。
Option Strict On
Imports System
Module Program
Sub Main()
Dim y,m,t As Integer
begin:
' 輸入數(shù)據(jù)時一行一個
y=CInt(Console.ReadLine())
m=CInt(Console.ReadLine())
t=CInt(Console.ReadLine())
If y
200 Then
Console.WriteLine("ERROR")
goto begin
End If
pr(y,m,t)
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
End Sub
Function pr(y As Integer,m As Integer,t As Integer) As Integer
Dim ye,[Me],i As Integer
ye=CInt((m+t-2)/12+y)
[Me]=(m+t-2) Mod 12+1
End If
End Function
Function mday(y As Integer,m As Integer) As Integer
Dim day As Integer()={0,31,28,31,30,31,30,31,31,30,31,30,31}
Dim ad As I
在c語言中每一個變量都有兩個屬性一個是值,一個是址。比如inta=2;變量a的值是2,變量a的地址,可以用取地址
操作符
獲取,即a。因此以C語言的函數(shù)傳遞中具備兩種方式傳遞參數(shù),一種是傳址,一種傳值。比如voidf1(intv){;}//函數(shù)f1v
首先是C的DLL(我的項目叫ConsoleApplication2.dll):
#include?Windows.h
//?導出Test函數(shù),供外部使用
extern?"C"?__declspec(dllexport)?BSTR?__cdecl?Test(LPSTR?p);
BOOL?WINAPI?DllMain(
HINSTANCE?hinstDLL,
DWORD?fdwReason,
LPVOID?lpReserved)
{
switch?(fdwReason)
{
case?DLL_PROCESS_ATTACH:?break;
case?DLL_THREAD_ATTACH:?break;
case?DLL_THREAD_DETACH:?break;
case?DLL_PROCESS_DETACH:?break;
}
return?TRUE;
}
BSTR?__cdecl?Test(LPSTR?p)
{
p[0]?=?'X';
return?SysAllocString((BSTR)p);
}
然后是VB.Net項目:
Imports?System.Runtime.InteropServices
Imports?System.Text
Module?Module1
REM?生成的是ConsoleApplication2.dll,名字與C里面相同
DllImport("ConsoleApplication2.dll",?CharSet:=CharSet.Auto,?CallingConvention:=CallingConvention.Cdecl)
Public?Function?Test(MarshalAs(UnmanagedType.LPTStr)?ByVal?str?As?StringBuilder)?As?MarshalAs(UnmanagedType.BStr)?String
End?Function
Sub?Main()
Dim?str?As?StringBuilder?=?New?StringBuilder("Hello")
Dim?rstr?As?String?=?Test(str)
Console.WriteLine(rstr)
Console.ReadKey()
End?Sub
End?Module
運行結(jié)果: