2012-08-13 4 views
1

Sqlite3 데이터베이스에 액세스하는 어셈블러에 작은 라이브러리를 작성해야하므로 sqlite3.dll을 사용하는 방법에 대한 검색을 시작했습니다. 나는 fasm에서 그것을 할 수있는 방법을 발견했다. (나는 문제를 해결하는 데 기여하지 않는 많은 이유 때문에 masm32를 사용해야한다. 그것은 단지 필요성이다.) cinvoke을 통해 가능하지 않은 라이브러리를 참조하는 것처럼 보인다.
내가 기본적으로 알고 싶은 것은 masm에서 비슷한 일을 할 수 있는지 또는 GetProcAddress을 통해 개별적으로 전화해야하는 모든 기능의 주소를 얻어야하는지 여부입니다.Windows에서 masm32와 함께 sqlite3을 사용하는 방법

답변

0

왜 그렇습니까? 나는 makefile을 사용

.486 
.model flat, stdcall 
option casemap:none 

include \masm32\include\masm32.inc 
include \masm32\include\kernel32.inc 
include \masm32\include\user32.inc 
include sqlite3.inc 

.data 
szSQLDB   db "MyDB.db3", 0 
szRandQuery  db "SELECT * FROM Quit ORDER BY RANDOM() LIMIT 1;", 0 

.data? 
hDBase   dd ? 

.code 
START: 
    invoke sqlite3_open, offset szSQLDB, offset hDBase 

    call GetQuitMsg 

    invoke sqlite3_close, hDBase 

    invoke ExitProcess, 0 

GetQuitMsg proc 
local ppStmt 

    invoke sqlite3_prepare_v2, hDBase, offset szRandQuery, -1, addr ppStmt, 0 
    invoke sqlite3_step, ppStmt 
    invoke sqlite3_data_count, ppStmt 
    .if eax !=0 
     invoke sqlite3_column_text, ppStmt, 0 
     invoke MessageBoxA, 0, eax, 0,0   
    .endif   
    ret 
GetQuitMsg endp 
end START 

, 내 편집기로 Geany : 그것은 다음과 같이 간단하게, 간단합니다. zip에는 테스트 db, sqlite3.inc가 포함되어 있지만 sqlite3.dll은 파일 압축을 풀지 않고 sqlite3.dll을 프로젝트 디렉토리에 넣으면 잘 될 것입니다. 또한 MS 링크를 사용하지 않고 가져 오기 라이브러리가 필요 없기 때문에 GoLink를 사용합니다. 그러나 MS 링크를 사용해야 할 경우 여기 어딘가에 SQLite 가져 오기 라이브러리가 있습니다.

http://www.gunnerinc.com/files/SQLiteTest.zip

0

살람,

그것은 내 예제 코드 : 그것은 'DBI'라는 이름의 테이블을 생성, 이름 '파일을 - file.db'와 데이터베이스 파일을 작성하고 삽입합니다

.386 
.model flat, stdcall 
option casemap:none 

include windows.inc 
include advapi32.inc 
include comctl32.inc 
include kernel32.inc 
include shell32.inc 
include user32.inc 

includelib advapi32.lib 
includelib comctl32.lib 
includelib kernel32.lib 
includelib shell32.lib 
includelib user32.lib 

.const 
    SQLITE_ROW equ 100 
.data? 
    dwResult dd ? 
    hDB dd ? 
    sqlite3_close dd ? 
    sqlite3_column_text dd ? 
    sqlite3_exec dd ? 
    sqlite3_open dd ? 
    sqlite3_prepare dd ? 
    sqlite3_step dd ? 
.data 
    szSQLite3Lib db "sqlite3.dll", 0h 
    szfnSQLite3_close db "sqlite3_close", 0h 
    szfnSQLite3_column_text db "sqlite3_column_text", 0h 
    szfnSQLite3_exec db "sqlite3_exec", 0h 
    szfnSQLite3_open db "sqlite3_open", 0h 
    szfnSQLite3_prepare db "sqlite3_prepare", 0h 
    szfnSQLite3_step db "sqlite3_step", 0h 
    szDBFile db "file.db", 0h 
    szSQLStmt1 db "create table DBI (nID integer primary key, szName text)", 0h 
    szSQLStmt2 db "insert into DBI (nID, szName) values (1, 'RizonBarns')", 0h 
    szSQLStmt3 db "insert into DBI (szName) values ('Rizon & Barns')", 0h 
    szSQLStmt4 db "insert into DBI (szName) values ('MASM32')", 0h 
    szSQLStmt5 db "select * from DBI", 0h 
.code 
main: 
    push offset szSQLite3Lib 
    call LoadLibraryA 
    cmp eax, 0h 
    je @ERROR 
    push offset szfnSQLite3_close 
    push eax 
    call GetProcAddress 
    mov sqlite3_close, eax 

    push offset szSQLite3Lib 
    call LoadLibraryA 
    push offset szfnSQLite3_column_text 
    push eax 
    call GetProcAddress 
    mov sqlite3_column_text, eax 

    push offset szSQLite3Lib 
    call LoadLibraryA 
    push offset szfnSQLite3_exec 
    push eax 
    call GetProcAddress 
    mov sqlite3_exec, eax 

    push offset szSQLite3Lib 
    call LoadLibraryA 
    push offset szfnSQLite3_open 
    push eax 
    call GetProcAddress 
    mov sqlite3_open, eax 

    push offset szSQLite3Lib 
    call LoadLibraryA 
    push offset szfnSQLite3_prepare 
    push eax 
    call GetProcAddress 
    mov sqlite3_prepare, eax 

    push offset szSQLite3Lib 
    call LoadLibraryA 
    push offset szfnSQLite3_step 
    push eax 
    call GetProcAddress 
    mov sqlite3_step, eax 

    push 255 
    push GPTR 
    call GlobalAlloc 
    mov hDB, eax 

    lea edx, hDB 
    push edx 
    push offset szDBFile 
    call sqlite3_open 

    push 0h 
    push 0h 
    push 0h 
    push offset szSQLStmt1 
    push hDB 
    call sqlite3_exec 

    push 0h 
    push 0h 
    push 0h 
    push offset szSQLStmt2 
    push hDB 
    call sqlite3_exec 

    push 0h 
    push 0h 
    push 0h 
    push offset szSQLStmt3 
    push hDB 
    call sqlite3_exec 

    push 0h 
    push 0h 
    push 0h 
    push offset szSQLStmt4 
    push hDB 
    call sqlite3_exec 

    push 0h 
    lea eax, dwResult 
    push eax 
    push offset szSQLStmt5 
    call lstrlenA 
    push eax 
    push offset szSQLStmt5 
    push hDB 
    call sqlite3_prepare 

@@: 
    push dwResult 
    call sqlite3_step 
    cmp eax, SQLITE_ROW 
    jne @F 
    push 0h 
    push dwResult 
    call sqlite3_column_text 
    mov esi, eax 
    push 1h 
    push dwResult 
    call sqlite3_column_text 
    mov edi, eax 
    push 0h 
    push esi 
    push edi 
    push 0h 
    call MessageBoxA 
    jmp @B 
@@: 
    push hDB 
    call sqlite3_close 
@ERROR: 
    xor eax, eax 
    push eax 
    call ExitProcess 
end main 

입니다 데이터는 3 행만큼. 데이터를 세 번 삽입하면 MessageBoxA에 데이터가 표시됩니다. 캡션으로 nID, 텍스트로 szName.

추가하십시오

이 MASM 설치 경로, LIB 및 BIN 환경을 포함 내 코드 :)으로 즐기고.

예 : \ MASM32 \

lib에는

BIN = C : \ MASM32 \ 빈

그리고이 있는지 확인 \ MASM32 \이

LIB = C를 포함

는 = C는 포함 명령 프롬프트에 을 입력하면 위의 경로가 표시됩니다.

와 살람.

관련 문제