Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Creating a Windows DLL with Visual Basic
Subject:   DLL works in VB exe but not in VBA
Date:   2005-11-22 06:12:37
From:   mike2508
I created the following function within a dll, for getting the value of a key in the registry, for an excel add-in my company uses (I had to use this method for reading the registry because our IT dept has restricted access to the registry for users, and therefore neither windows registry API calls, nor the use of "WScript.Shell" work) :



Public Function GetLastUserName() As String


Const HKEY_CURRENT_USER = &H80000001
Dim objReg As Object
Dim strValue As String, strKeyPath As String, strComputer As String

On Error GoTo EndGetUserFunction


strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "The registry path to the key"


objReg.GetStringValue HKEY_CURRENT_USER, strKeyPath, "User", strValue
GetLastUserName = StrConv(strValue, vbFromUnicode)


EndGetUserFunction:
Set objReg = Nothing


End Function


The DLL works ok if I use it in a visual basic exe, but when I try to use it in Excel VBA, Excel crashes. I dont know why


How can I resolve this issue?


Regards
Mike

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • DLL works in VB exe but not in VBA
    2006-01-17 22:44:12  mandanaL [View]

    Dear friend, I have similar problem in VB.net and C++ application with DLL.
    can you tell me how you solved your problem.
    Thanks
    Mandana
    • DLL works in VB exe but not in VBA
      2007-08-28 02:31:35  Lukie [View]

      I see it's been already a year and a half, but were you able to solve this problem (passing and returning strings from VBA to and from Windows DLL written in VB6) ?