Criação de Fonte de dados ODBC no windows 2000
Oi, tenho um programa que cria a fonte de dados ODBC no win98 gostaria se saber se é possível alterar o código para fazer o mesmo no 2000, o código é o seguinte:
implementation
{$R *.DFM}
procedure CreateODBCDriver(Const cDSNName,cExclusive,cDescription,cDataBase,cDefaultPath,cConfigSql,cDriver: string);
type
TSQLConfigDataSource = function( hwndParent: HWND; fRequest: WORD; lpszDriver: LPCSTR;
lpszAttributes: LPCSTR ): BOOL; stdcall;
const
ODBC_ADD_DSN = 1; // Adiciona uma fonte de dados (data source)
ODBC_CONFIG_DSN = 2; // Configura a fonte de dados (data source)
ODBC_REMOVE_DSN = 3; // Remove a fonte de dados (data source)
ODBC_ADD_SYS_DSN = 4; // Adiciona um DSN no sistema
ODBC_CONFIG_SYS_DSN = 5; // Configura o DSN do sistema
ODBC_REMOVE_SYS_DSN = 6; // Remove o DSN do sistema
var
pFn: TSQLConfigDataSource;
hLib: LongWord;
strDriver: string;
strHome: string;
strAttr: string;
strFile: string;
fResult: BOOL;
ModName: array[0..MAX_PATH] of Char;
srInfo : TSearchRec;
begin
Windows.GetModuleFileName( HInstance, ModName, SizeOf(ModName) );
strHome := ModName;
while ( strHome[length(strHome)] <> ´\´ ) do
Delete( strHome, length(strHome), 1 );
strhome := ´c:\RMB\Dados\´;
strFile := strHome + cDatabase; // Teste com access (Axes = Access)
hLib := LoadLibrary( pChar(cDefaultPath) ); // carregando para o diretório padrão
if( hLib <> NULL ) then
begin
@pFn := GetProcAddress( hLib, pChar(cConfigSql) );
if( @pFn <> nil ) then
begin
strDriver := cDriver;
strAttr := Format( ´DSN=¬s´+#0+
´DBQ=¬s´+0+
´Exclusive=¬s´+0+
´Description=¬s´+0+0,
[cDSNName,strFile,cExclusive,cDescription] );
fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
if( fResult = false ) then
ShowMessage( ´Falha ao tentar criar o DSN (Data source).´ );
if( FindFirst( strFile, 0, srInfo ) <> 0 ) then
begin
strDriver := cDriver;
strAttr := Format( ´DSN=¬s´+#0+
´DBQ=¬s´+0+
´Exclusive=¬s´+0+
´Description= ¬s´+0+0+
´CREATE_DB=´¬s´´0+0,
[cDSNName,strFile,cExclusive,cDescription,strFile]);
fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
if( fResult = false ) then
ShowMessage( ´Falha ao tentar criar o banco de dados´ );
end;
FindClose( srInfo );
end;
FreeLibrary( hLib );
if fResult then
ShowMessage( ´Banco de dados criado !´ );
end
else
begin
ShowMessage( ´o sistema não pode carregar a biblioteca ODBCCP32.DLL´ );
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
CreateOdbcDriver(´RMB_A´,´0´,´´,´RMB.MDB´,´ODBCCP32´,´SQLConfigDataSource´,´Driver para o Microsoft Access (*.mdb)´);
end;
end.
implementation
{$R *.DFM}
procedure CreateODBCDriver(Const cDSNName,cExclusive,cDescription,cDataBase,cDefaultPath,cConfigSql,cDriver: string);
type
TSQLConfigDataSource = function( hwndParent: HWND; fRequest: WORD; lpszDriver: LPCSTR;
lpszAttributes: LPCSTR ): BOOL; stdcall;
const
ODBC_ADD_DSN = 1; // Adiciona uma fonte de dados (data source)
ODBC_CONFIG_DSN = 2; // Configura a fonte de dados (data source)
ODBC_REMOVE_DSN = 3; // Remove a fonte de dados (data source)
ODBC_ADD_SYS_DSN = 4; // Adiciona um DSN no sistema
ODBC_CONFIG_SYS_DSN = 5; // Configura o DSN do sistema
ODBC_REMOVE_SYS_DSN = 6; // Remove o DSN do sistema
var
pFn: TSQLConfigDataSource;
hLib: LongWord;
strDriver: string;
strHome: string;
strAttr: string;
strFile: string;
fResult: BOOL;
ModName: array[0..MAX_PATH] of Char;
srInfo : TSearchRec;
begin
Windows.GetModuleFileName( HInstance, ModName, SizeOf(ModName) );
strHome := ModName;
while ( strHome[length(strHome)] <> ´\´ ) do
Delete( strHome, length(strHome), 1 );
strhome := ´c:\RMB\Dados\´;
strFile := strHome + cDatabase; // Teste com access (Axes = Access)
hLib := LoadLibrary( pChar(cDefaultPath) ); // carregando para o diretório padrão
if( hLib <> NULL ) then
begin
@pFn := GetProcAddress( hLib, pChar(cConfigSql) );
if( @pFn <> nil ) then
begin
strDriver := cDriver;
strAttr := Format( ´DSN=¬s´+#0+
´DBQ=¬s´+0+
´Exclusive=¬s´+0+
´Description=¬s´+0+0,
[cDSNName,strFile,cExclusive,cDescription] );
fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
if( fResult = false ) then
ShowMessage( ´Falha ao tentar criar o DSN (Data source).´ );
if( FindFirst( strFile, 0, srInfo ) <> 0 ) then
begin
strDriver := cDriver;
strAttr := Format( ´DSN=¬s´+#0+
´DBQ=¬s´+0+
´Exclusive=¬s´+0+
´Description= ¬s´+0+0+
´CREATE_DB=´¬s´´0+0,
[cDSNName,strFile,cExclusive,cDescription,strFile]);
fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
if( fResult = false ) then
ShowMessage( ´Falha ao tentar criar o banco de dados´ );
end;
FindClose( srInfo );
end;
FreeLibrary( hLib );
if fResult then
ShowMessage( ´Banco de dados criado !´ );
end
else
begin
ShowMessage( ´o sistema não pode carregar a biblioteca ODBCCP32.DLL´ );
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
CreateOdbcDriver(´RMB_A´,´0´,´´,´RMB.MDB´,´ODBCCP32´,´SQLConfigDataSource´,´Driver para o Microsoft Access (*.mdb)´);
end;
end.
Fellyne
Curtidas 0