Software Archive
Read-only legacy content
17061 Discussions

Reading registry values (2nd try)

Intel_C_Intel
Employee
588 Views
Sorry for posting a second time. The spell checker sort of wacked my first post...

I'm trying to read a string from the registry to implement design-time licensing in a COM DLL, which I've written in Fortran 6.5. I can successfully open the registry key, but when I try to read the REG_SZ value via RegQueryValueEx PI function, I get the following first-chance exception:
First-chance exception in OlisGW.exe (ADVAPI32.DLL): 0xC0000005: Access Violation.

I've used this same sort of licensing technique from I++ COM DLLs written in ATL, so I know the process works. Can anyone shed light on my problem? The code I am using is listed below.

Thanks,

Michael Gerfen


    ! 
    !  CanRequestLicenseKey 
    ! 
    function CanRequestLicenseKey result  
        use dfwin  
        implicit none 
        logical r 
        !  TODO:  Add code to determine if the class is design-time licensed  
        !         on this machine and we can return the license key in a  
        !         call to GetLicenseKey 
         
        integer(INT_PTR_KIND()) bstrKey 
        integer(INT_PTR_KIND()) bstrLicense 
        integer(LONG) hresult 
        integer(LONG) retval 
        integer(LONG) iLen 
        character(1024) license 
        integer hKey 
        iLen = 1024 
        if ( RegOpenKeyEx(HKEY_CURRENT_USER, Key, 0, & 
            KEY_QUERY_VALUE  , loc(hKey) ) == ERROR_SUCCESS) then  
 
           !this line causes the first-chance exception 
           retval = RegQueryValueEx( hKey, "Fortran License"C, NULL, 1, loc(license), loc(iLen) )    
 
           bstrLicense = ConvertStringToBSTR(license) 
 
        
           hresult = GetLicenseKey(bstrKey) 
           if (bstrLicense .EQ. bstrKey) Then  
               r = .TRUE. 
           else 
               r = .FALSE. 
           end if             
 
        end if 
    end function

0 Kudos
2 Replies
Intel_C_Intel
Employee
588 Views
The fourth parameter to RegQueryValueEx is an out parameter. Pass either NULL or loc(somevar).

hth,
John
0 Kudos
Intel_C_Intel
Employee
588 Views
John,

Doh! Thanks, that did the trick.

Regards,

Michael
0 Kudos
Reply