After copying the code for all four files, and successfully compiling it, I get a runtime error
===
the procedure entry point sqlallochandle could not be located in ODBC32.dll
===
On my system ODBC32.dll is located in the System32 folder.
I tried both approaches as mentioned in the text (copied below for convienient reference), but I get this run time error both ways.
=========================================================
=========================================================
'*******************************************
'file name: showdata.inc (2nd of 4)
'*******************************************
'************************************************* *************************************************
'this is essentially the main include file for the application showdata.bas. i find that in a major
'application containing many forms/dialogs there will be common functions that aren't specific to any
'particular form. these routines can be kept in a main include file such as this. also, types,
'equates and global variables can go there too. in this particular application i put in here the
'only two global variables, several equates (the control ids for the buttons, list box and text box),
'and the type i use to pass the window procedure parameters to message handlers. here they are...
'************************************************* *************************************************
Code:
global sztextboxdisplay as asciiz*16 'holds the class name string 'frmtextbox'
global szlistboxdisplay as asciiz*16 'holds the class name string 'frmlistbox'
%idc_button_1=1001 'ctrl id for button on frmmainwindow. goes in 9th parameter of createwindow() call.
%idc_button_2=1002 'ctrl id for button on frmmainwindow. goes in 9th parameter of createwindow() call.
%idc_edit_box=1003 'control id for text/edit box
%idc_list_box=1004 'control id for listbox
%idc_lb_load =1005 'control id for button at bottom of frmlistbox
type wndeventargs 'type holds parameters for window procedure
hins as dword
hwnd as dword
wparam as dword
lparam as dword
end type'************************************************* *************************************************
'also with this file i included the odbc equates and function declarations i needed to make this app
'work in the absence of including the three main odbc includes along with the includes at the top
'of showdata.bas (the main program file). i didn't want to force my readers into having to go to the
'internet (at www.powerbasic.com) to download special files (the odbc includes) just to get this app
'to work, so i pulled four function declarations and eight equates out of the odbc includes, and am
'including them right here in the source code of showdata.inc. here they are...
'************************************************* *************************************************
Code:
'odbc equates and function declarations needed to make sqldrivers() work.
%sql_null_handle = 0&
%sql_handle_env = 1
%sql_attr_odbc_version = 200
%sql_ov_odbc3 = 3???
%sql_is_integer = (-6)
%sql_fetch_next = 1
%sql_no_data = 100
%sql_error = -1
'
declare function sqlallochandle lib "odbc32.dll" alias "sqlallochandle" _
( _
byval handletype as integer,_
byval inputhandle as dword,_
byref outputhandle as dword _
) as integer
'
declare function sqlsetenvattr lib "odbc32.dll" alias "sqlsetenvattr" _
( _
byval environmenthandle as dword,_
byval attribute as long,_
byref value as any,_
byval stringlength as long _
) as integer
'
declare function sqldrivers lib "odbc32.dll" alias "sqldrivers" _
( _
byval henv as dword,_
byval fdirection as word,_
byref szdriverdesc as asciiz,_
byval cbdriverdescmax as integer,_
byref pcbdriverdesc as integer,_
byref szdriverattributes as asciiz,_
byval cbdrvrattrmax as integer,_
byref pcbdrvrattr as integer _
) as integer
'
declare function sqlfreehandle lib "odbc32.dll" alias "sqlfreehandle" _
( _
byval handletype as integer,_
byval thehandle as dword _
) as integer'************************************************* *************************************************
'now the situation with these odbc equates and declares is this. if by some chance you might be
'interested in learning to use the odbc api functions to work with databases, then you really should
'go to...
'
' http://www.powerbasic.com/files/pub/...e/pbodbc30.zip
'
'and get the three necessary odbc includes for your work. the three necessary includes are
'sqltypes.inc, sql32.inc and sqlext32.inc. if you get those files from the pb downloads then you can
'modify this app to use them instead of the 41 lines of code listed above. in that case just delete
'those eight equates and four function declarations and change the includes at the top of showdata.bas
'like so...
'************************
'file name: showdata.bas
'************************
'
'************************************************* *****************************************
'#compile exe
'#dim all
'#include "win32api.inc" '<<this file is courtesy of powerbasic and you should be thankful for it
'#include "sqltypes.inc" '<<odbc include !!!!!
'#include "sql32.inc" '<<odbc include !!!!!
'#include "sqlext32.inc"' '<<odbc include !!!!!
'#include "showdata.inc" '<<my main include for app equates, declares and functions
'#include "frmtextbox.inc" '<<my include that contains code for the text/edit box form
'#include "frmlistbox.inc" '<<my include that contains code for the list box form
'************************************************* *****************************************
'if you check back in showdata.bas you'll see those three odbc includes are missing, but this
'app should work fine without them as i copied the necessary equates and declares directly
'into the code here. but if you don't get those includes from powerbasic don't delete those
'lines or this app won't even comple much less run!
'************************************************* *****************************************
'************************************************* ****************************************
'function name: blngetsqldriverdata(heditbox as dword) as long
'purpose: sets up odbc environment for calls to sqldrivers
' and fills text box with driver names and driver
' attribute-value pairs
'return value %true or %false indicating success or failure
'parameters one parameter - handle to edit box to fill with
' driver descriptions and driver attribute values
'************************************************* *****************************************
'the purpose of this application is just to show you how to load data into a text box or
'list box using sdk style code and calling windows api functions. i mentioned in
'frmtextbox.inc that for that purpose you could consider what goes on in this particular
'function as an inscrutable 'black box' out of which data flows faithfully if not somewhat
'mysteriously. but if you want a very detailed blow by blow description of how this function
'works, see the following post in source code:
'
'sqldrivers() demo http://www.powerbasic.com/support/pb...ad.php?t=25068
'
'************************************************* *****************************************
Code:
function blngetsqldriverdata(heditbox as dword) as long
local ilen1 as integer,ilen2 as integer
local szdriverattr as asciiz*256
local szdriverdes as asciiz*64
local ptrbyte as byte ptr
local strarr() as string
local strtext as string
local henvr as dword
register i as long
'
if sqlallochandle(%sql_handle_env,%sql_null_handle,henvr)<>%sql_error then
call sqlsetenvattr(henvr,%sql_attr_odbc_version,byval %sql_ov_odbc3,%sql_is_integer)
while sqldrivers(henvr,%sql_fetch_next,szdriverdes,64,ilen1,szdriverattr,256,ilen2)<>%sql_no_data
strtext=strtext & szdriverdes & chr$(13,10) & chr$(13,10)
decr ilen2 'convert one based count of bytes to zero basing for pointer use.
ptrbyte=varptr(szdriverattr) 'loop through szdriverattr buffer one byte at a time for ilen2 bytes
for i=0 to ilen2 'substituting commas ( chr$(44) ) for null bytes. ilen1 and ilen2
if @ptrbyte[i]=0 then 'are output parameters in sqldrivers() odbc function call. then
@ptrbyte[i]=44 'powerbasic's parse statement will parse driver attribute pairs into
end if 'string array for output. 'the last byte at ilen2 was a null that
next i 'got turned into a comma, so lets remove it. storing a null byte
@ptrbyte[ilen2]=0 'there will also decrease length of string by one.
redim strarr(parsecount(szdriverattr)-1) 'parsecount returns a one based count, but parse
parse szdriverattr,strarr() 'starts storing parsed strings into element zero
for i=0 to ubound(strarr,1) 'of strarr(), so it is best to use parsecount - 1.
strtext=strtext & strarr(i) & chr$(13,10) 'add crlf after each string to get them into seperate
next i 'lines.
strtext=strtext & chr$(13,10) & chr$(13,10)
loop
call sqlfreehandle(%sql_handle_env,henvr)
call setwindowtext(heditbox,byval strptr(strtext))
blngetsqldriverdata=%true
else
blngetsqldriverdata=%false
end if
end function
===
the procedure entry point sqlallochandle could not be located in ODBC32.dll
===
On my system ODBC32.dll is located in the System32 folder.
I tried both approaches as mentioned in the text (copied below for convienient reference), but I get this run time error both ways.
=========================================================
=========================================================
'*******************************************
'file name: showdata.inc (2nd of 4)
'*******************************************
'************************************************* *************************************************
'this is essentially the main include file for the application showdata.bas. i find that in a major
'application containing many forms/dialogs there will be common functions that aren't specific to any
'particular form. these routines can be kept in a main include file such as this. also, types,
'equates and global variables can go there too. in this particular application i put in here the
'only two global variables, several equates (the control ids for the buttons, list box and text box),
'and the type i use to pass the window procedure parameters to message handlers. here they are...
'************************************************* *************************************************
Code:
global sztextboxdisplay as asciiz*16 'holds the class name string 'frmtextbox'
global szlistboxdisplay as asciiz*16 'holds the class name string 'frmlistbox'
%idc_button_1=1001 'ctrl id for button on frmmainwindow. goes in 9th parameter of createwindow() call.
%idc_button_2=1002 'ctrl id for button on frmmainwindow. goes in 9th parameter of createwindow() call.
%idc_edit_box=1003 'control id for text/edit box
%idc_list_box=1004 'control id for listbox
%idc_lb_load =1005 'control id for button at bottom of frmlistbox
type wndeventargs 'type holds parameters for window procedure
hins as dword
hwnd as dword
wparam as dword
lparam as dword
end type'************************************************* *************************************************
'also with this file i included the odbc equates and function declarations i needed to make this app
'work in the absence of including the three main odbc includes along with the includes at the top
'of showdata.bas (the main program file). i didn't want to force my readers into having to go to the
'internet (at www.powerbasic.com) to download special files (the odbc includes) just to get this app
'to work, so i pulled four function declarations and eight equates out of the odbc includes, and am
'including them right here in the source code of showdata.inc. here they are...
'************************************************* *************************************************
Code:
'odbc equates and function declarations needed to make sqldrivers() work.
%sql_null_handle = 0&
%sql_handle_env = 1
%sql_attr_odbc_version = 200
%sql_ov_odbc3 = 3???
%sql_is_integer = (-6)
%sql_fetch_next = 1
%sql_no_data = 100
%sql_error = -1
'
declare function sqlallochandle lib "odbc32.dll" alias "sqlallochandle" _
( _
byval handletype as integer,_
byval inputhandle as dword,_
byref outputhandle as dword _
) as integer
'
declare function sqlsetenvattr lib "odbc32.dll" alias "sqlsetenvattr" _
( _
byval environmenthandle as dword,_
byval attribute as long,_
byref value as any,_
byval stringlength as long _
) as integer
'
declare function sqldrivers lib "odbc32.dll" alias "sqldrivers" _
( _
byval henv as dword,_
byval fdirection as word,_
byref szdriverdesc as asciiz,_
byval cbdriverdescmax as integer,_
byref pcbdriverdesc as integer,_
byref szdriverattributes as asciiz,_
byval cbdrvrattrmax as integer,_
byref pcbdrvrattr as integer _
) as integer
'
declare function sqlfreehandle lib "odbc32.dll" alias "sqlfreehandle" _
( _
byval handletype as integer,_
byval thehandle as dword _
) as integer'************************************************* *************************************************
'now the situation with these odbc equates and declares is this. if by some chance you might be
'interested in learning to use the odbc api functions to work with databases, then you really should
'go to...
'
' http://www.powerbasic.com/files/pub/...e/pbodbc30.zip
'
'and get the three necessary odbc includes for your work. the three necessary includes are
'sqltypes.inc, sql32.inc and sqlext32.inc. if you get those files from the pb downloads then you can
'modify this app to use them instead of the 41 lines of code listed above. in that case just delete
'those eight equates and four function declarations and change the includes at the top of showdata.bas
'like so...
'************************
'file name: showdata.bas
'************************
'
'************************************************* *****************************************
'#compile exe
'#dim all
'#include "win32api.inc" '<<this file is courtesy of powerbasic and you should be thankful for it
'#include "sqltypes.inc" '<<odbc include !!!!!
'#include "sql32.inc" '<<odbc include !!!!!
'#include "sqlext32.inc"' '<<odbc include !!!!!
'#include "showdata.inc" '<<my main include for app equates, declares and functions
'#include "frmtextbox.inc" '<<my include that contains code for the text/edit box form
'#include "frmlistbox.inc" '<<my include that contains code for the list box form
'************************************************* *****************************************
'if you check back in showdata.bas you'll see those three odbc includes are missing, but this
'app should work fine without them as i copied the necessary equates and declares directly
'into the code here. but if you don't get those includes from powerbasic don't delete those
'lines or this app won't even comple much less run!
'************************************************* *****************************************
'************************************************* ****************************************
'function name: blngetsqldriverdata(heditbox as dword) as long
'purpose: sets up odbc environment for calls to sqldrivers
' and fills text box with driver names and driver
' attribute-value pairs
'return value %true or %false indicating success or failure
'parameters one parameter - handle to edit box to fill with
' driver descriptions and driver attribute values
'************************************************* *****************************************
'the purpose of this application is just to show you how to load data into a text box or
'list box using sdk style code and calling windows api functions. i mentioned in
'frmtextbox.inc that for that purpose you could consider what goes on in this particular
'function as an inscrutable 'black box' out of which data flows faithfully if not somewhat
'mysteriously. but if you want a very detailed blow by blow description of how this function
'works, see the following post in source code:
'
'sqldrivers() demo http://www.powerbasic.com/support/pb...ad.php?t=25068
'
'************************************************* *****************************************
Code:
function blngetsqldriverdata(heditbox as dword) as long
local ilen1 as integer,ilen2 as integer
local szdriverattr as asciiz*256
local szdriverdes as asciiz*64
local ptrbyte as byte ptr
local strarr() as string
local strtext as string
local henvr as dword
register i as long
'
if sqlallochandle(%sql_handle_env,%sql_null_handle,henvr)<>%sql_error then
call sqlsetenvattr(henvr,%sql_attr_odbc_version,byval %sql_ov_odbc3,%sql_is_integer)
while sqldrivers(henvr,%sql_fetch_next,szdriverdes,64,ilen1,szdriverattr,256,ilen2)<>%sql_no_data
strtext=strtext & szdriverdes & chr$(13,10) & chr$(13,10)
decr ilen2 'convert one based count of bytes to zero basing for pointer use.
ptrbyte=varptr(szdriverattr) 'loop through szdriverattr buffer one byte at a time for ilen2 bytes
for i=0 to ilen2 'substituting commas ( chr$(44) ) for null bytes. ilen1 and ilen2
if @ptrbyte[i]=0 then 'are output parameters in sqldrivers() odbc function call. then
@ptrbyte[i]=44 'powerbasic's parse statement will parse driver attribute pairs into
end if 'string array for output. 'the last byte at ilen2 was a null that
next i 'got turned into a comma, so lets remove it. storing a null byte
@ptrbyte[ilen2]=0 'there will also decrease length of string by one.
redim strarr(parsecount(szdriverattr)-1) 'parsecount returns a one based count, but parse
parse szdriverattr,strarr() 'starts storing parsed strings into element zero
for i=0 to ubound(strarr,1) 'of strarr(), so it is best to use parsecount - 1.
strtext=strtext & strarr(i) & chr$(13,10) 'add crlf after each string to get them into seperate
next i 'lines.
strtext=strtext & chr$(13,10) & chr$(13,10)
loop
call sqlfreehandle(%sql_handle_env,henvr)
call setwindowtext(heditbox,byval strptr(strtext))
blngetsqldriverdata=%true
else
blngetsqldriverdata=%false
end if
end function
Comment