Loading ...
Sorry, an error occurred while loading the content.

Help with dll call

Expand Messages
  • neilrichardcorcoran
    I m trying to put together a program that uses the registry. I ve tried to convert the VB syntax into LB but I keep getting a Dynamic Link Library Call
    Message 1 of 6 , Mar 1, 2002
    • 0 Attachment
      I'm trying to put together a program that uses the registry. I've
      tried to convert the VB syntax into LB but I keep getting a 'Dynamic
      Link Library Call Error'. Any suggestions on what I did wrong.

      The original Visual Basic syntax:

      Declare Function RegOpenKeyEx Lib "advapi32.dll"
      Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String,
      ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long)
      As Long

      My Liberty Basic translation:

      Open "Advapi32" for dll as #Advapi32

      CallDll #Advapi32, "RegOpenKeyEx",_
      hKey as Long,_
      lpSubKey$ as ptr,_
      uloptions as long,_
      samDesired as long,_
      phkResult As long,_
      result as long

      For more documentation:
      http://www.vbapi.com/ref/funcc.html#registry
    • Doyle Whisenant
      ... Try using: RegOpenKeyExA ... -- Doyle Whisenant mechanic@sonet.net http://www.mechanic.0catch.com/
      Message 2 of 6 , Mar 1, 2002
      • 0 Attachment
        neilrichardcorcoran wrote:
        >
        > I'm trying to put together a program that uses the registry. I've
        > tried to convert the VB syntax into LB but I keep getting a 'Dynamic
        > Link Library Call Error'. Any suggestions on what I did wrong.
        >
        >
        > Open "Advapi32" for dll as #Advapi32
        >
        > CallDll #Advapi32, "RegOpenKeyEx",_

        Try using: RegOpenKeyExA

        > hKey as Long,_
        > lpSubKey$ as ptr,_
        > uloptions as long,_
        > samDesired as long,_
        > phkResult As long,_
        > result as long
        >

        --
        Doyle Whisenant
        mechanic@...
        http://www.mechanic.0catch.com/
      • watson
        ... I see that Doyle has answered your question. Just a word of warning. If you foul the registry, your system may become unusable. Be sure to back up your
        Message 3 of 6 , Mar 1, 2002
        • 0 Attachment
          At 09:56 AM 3/1/02 -0000, you wrote:
          >I'm trying to put together a program that uses the registry.

          I see that Doyle has answered your question. Just a word of warning. If
          you foul the registry, your system may become unusable. Be sure to back up
          your registry before testing this stuff. Also, please let us know that you
          will be writing to the registry if you distribute your program to the
          group. Some people are very reluctanct to have their registry changed.
          (I'll admit that I am one of them.)

          Good luck,
          Alyce
        • Cor Massar
          It works when you use the Alias name. Cor
          Message 4 of 6 , Mar 1, 2002
          • 0 Attachment
            It works when you use the Alias name.

            Cor

            neilrichardcorcoran wrote:

            > I'm trying to put together a program that uses the registry. I've
            > tried to convert the VB syntax into LB but I keep getting a 'Dynamic
            > Link Library Call Error'. Any suggestions on what I did wrong.
            >
            > The original Visual Basic syntax:
            >
            > Declare Function RegOpenKeyEx Lib "advapi32.dll"
            > Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String,
            > ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long)
            > As Long
            >
            > My Liberty Basic translation:
            >
            > Open "Advapi32" for dll as #Advapi32
            >
            > CallDll #Advapi32, "RegOpenKeyEx",_
            > hKey as Long,_
            > lpSubKey$ as ptr,_
            > uloptions as long,_
            > samDesired as long,_
            > phkResult As long,_
            > result as long
            >
            > For more documentation:
            > http://www.vbapi.com/ref/funcc.html#registry
            >
            >
            > To unsubscribe from this group, send an email to:
            > libertybasic-unsubscribe@egroups.com
            >
            >
            >
            > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
          • neilrichardcorcoran
            ... a Dynamic ... Thanks for the advice. I didn t realise the alias was different to the function name. Using the alias name stopped the Dynamic Link Library
            Message 5 of 6 , Mar 2, 2002
            • 0 Attachment
              --- In libertybasic@y..., Doyle Whisenant <mechanic@s...> wrote:
              > neilrichardcorcoran wrote:
              > >
              > > I'm trying to put together a program that uses the registry. I've
              > > tried to convert the VB syntax into LB but I keep getting
              a 'Dynamic
              > > Link Library Call Error'. Any suggestions on what I did wrong.
              > >
              > >
              > > Open "Advapi32" for dll as #Advapi32
              > >
              > > CallDll #Advapi32, "RegOpenKeyEx",_
              >
              > Try using: RegOpenKeyExA


              Thanks for the advice. I didn't realise the alias was different to
              the function name. Using the alias name stopped the 'Dynamic Link
              Library Call Error'. However the call isn't working successfully. I'm
              usaully pretty good at api calls in LB but this one is giving me
              trouble.

              It runs OK but the result is producing the number 87 which
              represents 'ERROR_INVALID_PARAMETER'. I've tried everything I can
              think of to fix it but it won't return a successful result. Does
              anyone know where I could find some source code to a program that
              uses the registry?
            • Doyle Whisenant
              ... I have code for EZwin, probably not what you want! I ll translate the relevant part for you. This is the call: ; open the registry RetValue =
              Message 6 of 6 , Mar 2, 2002
              • 0 Attachment
                neilrichardcorcoran wrote:
                >
                > Does anyone know where I could find some source code to a program that
                > uses the registry?

                I have code for EZwin, probably not what you want! I'll translate the
                relevant part for you.

                This is the call:

                ; open the registry
                RetValue = RegOpenKeyEx((HKEY)HKEY_CURRENT_USER,
                "Software\\lcc\\lcclnk", 0, KEY_READ, (HKEY)&hKey)

                IF RetValue <> ERROR_SUCCESS
                SHOW "Error" STR "Unable to open registry"
                END IF


                I've changed the EZwin syntax so that it is more "readable" for you! HTH

                ************************************************************************************
                The Whistler Platform SDK states:


                RegOpenKeyEx
                The RegOpenKeyEx function opens the specified registry key.

                LONG RegOpenKeyEx(
                HKEY hKey, // handle to open key
                LPCTSTR lpSubKey, // subkey name
                DWORD ulOptions, // reserved
                REGSAM samDesired, // security access mask
                PHKEY phkResult // handle to open key
                );

                Parameters

                hKey
                [in] Handle to a currently open key or any of the following predefined
                reserved handle values:
                HKEY_CLASSES_ROOT
                HKEY_CURRENT_CONFIG
                HKEY_CURRENT_USER
                HKEY_LOCAL_MACHINE
                HKEY_USERS
                Windows NT/2000: HKEY_PERFORMANCE_DATA
                Windows 95/98: HKEY_DYN_DATA

                lpSubKey
                [in] Pointer to a null-terminated string containing the name of the
                subkey to open. If this parameter is NULL or a pointer to an empty
                string, the function will open a new handle to the key identified by the
                hKey parameter. In this case, the function will not close the handles
                previously opened.

                ulOptions
                Reserved; must be zero.

                samDesired
                [in] An access mask that specifies the desired access rights to the key.
                This parameter can be a combination of the following values. Value
                Meaning
                KEY_CREATE_LINK Permission to create a symbolic link.
                KEY_CREATE_SUB_KEY Permission to create subkeys.
                KEY_ENUMERATE_SUB_KEYS Permission to enumerate subkeys.
                KEY_EXECUTE Permission for read access.
                KEY_NOTIFY Permission for change notification.
                KEY_QUERY_VALUE Permission to query subkey data.
                KEY_SET_VALUE Permission to set subkey data.
                KEY_ALL_ACCESS Combines the KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS,
                KEY_NOTIFY, KEY_CREATE_SUB_KEY, KEY_CREATE_LINK, and KEY_SET_VALUE
                access rights, plus all the standard access rights except SYNCHRONIZE.
                KEY_READ Combines the STANDARD_RIGHTS_READ, KEY_QUERY_VALUE,
                KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY access rights.
                KEY_WRITE Combines the STANDARD_RIGHTS_WRITE, KEY_SET_VALUE, and
                KEY_CREATE_SUB_KEY access rights.


                phkResult
                [out] Pointer to a variable that receives a handle to the opened key.
                When you no longer need the returned handle, call the RegCloseKey
                function to close it.
                Return Values
                If the function succeeds, the return value is ERROR_SUCCESS.

                If the function fails, the return value is a nonzero error code defined
                in Winerror.h. You can use the FormatMessage function with the
                FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the
                error.

                Remarks
                Unlike the RegCreateKeyEx function, the RegOpenKeyEx function does not
                create the specified key if the key does not exist in the registry.

                Windows 95/98: No registry subkey or value name may exceed 255
                characters.

                Requirements
                Windows NT/2000: Requires Windows NT 3.1 or later.
                Windows 95/98: Requires Windows 95 or later.
                Header: Declared in Winreg.h; include Windows.h.
                Library: Use Advapi32.lib.
                Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.


                --
                Doyle Whisenant
                mechanic@...
                http://www.mechanic.0catch.com/
              Your message has been successfully submitted and would be delivered to recipients shortly.