Create a DLL with VB.NET and use with VBScript

G

Guest

I don't know if this can be done, but here goes...

The following is a code snippet from VB 6 that I used to read/write to INI
files. Is it possible to create a DLL with .NET and use it with VBScript?
Where would I begin?



Option Explicit

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Public Function GetINIInfo(ByVal sSection As String, ByVal sKeyWord As
String, _
ByVal sDefVal As String, ByVal sINIFile As String) As String
Dim sTempVar As String * 256
Dim lRet As Long

'Get value from INI file
lRet = GetPrivateProfileString(CStr(sSection), CStr(sKeyWord),
CStr(sDefVal), sTempVar, 256, CStr(sINIFile))

'Strip off NULL and return value
If lRet > 0 Then
GetINIInfo = RTrim(Left$(Mid$(sTempVar, 1, lRet), InStr(sTempVar,
Chr$(0)) - 1))
Else
GetINIInfo = ""
End If
End Function

Public Function WriteINIInfo(ByVal sSection As String, ByVal sKeyWord As
String, _
ByVal sValue As String, ByVal sINIFile As String) As String
WriteINIInfo = WritePrivateProfileString(CStr(sSection), CStr(sKeyWord),
CStr(sValue), CStr(sINIFile))
End Function
 
P

Paul Clement

¤ I don't know if this can be done, but here goes...
¤
¤ The following is a code snippet from VB 6 that I used to read/write to INI
¤ files. Is it possible to create a DLL with .NET and use it with VBScript?
¤ Where would I begin?
¤

It's already been done:

http://www.mentalis.org/soft/class.qpx?id=6

To register the .NET DLL for COM interop you can use the Regasm tool:

http://msdn.microsoft.com/library/d...ml/cpgrfAssemblyRegistrationToolRegasmexe.asp


Paul
~~~~
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top