線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1542
推到 Plurk!
推到 Facebook!

如何使用BCB或Delphi寫MS-SQL 的ExtentedProcedures 的DLL ??

尚未結案
asupeduer
初階會員


發表:36
回覆:49
積分:27
註冊:2002-11-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-11-17 23:42:23 IP:61.13.xxx.xxx 未訂閱
//抱歉,先向站長自首,本文張重複PO,是因為之前PO在資料庫版一直沒有人回答,我想大概是貼錯地方了 請問如何使用BCB或Delphi寫MS-SQL 的ExtentedProcedures 的DLL 實做在讀取電子發票的發票號碼上...使用BCB5/SQL SERVER 2K 如題,我想在Trigger裡面寫交易,在訂單結案後自動讀取發票號碼, 如果發票資料表內有[有效/未使用]發票,就讀取發票,並且完成交易.... 如果發票資料表內已無[有效/未使用]發票,則跳到GOTO標籤,取消交易 並將訂單相關資料等取消,並ShowMessage("目前發票櫃中沒有發票, 請通知財務管理人員後再進行結案工作......") 看書看了老半天,雖然Trigger裡面無法直接ShowMessage到前端應用程式, 但是SQL Server可以用C 撰寫延伸預存程序ExtentedProcedures 直接呼叫 Windows下的原生功能,所以可能可以在 Trigger下寫 Exec xp_ShowMessage '訊息內容' Input 來讓前端程式呼叫一個Message 我查過SQL SERVER 2K線上叢書有撰寫DLL的方法,但是小弟功力太差, 還是不會用BCB或Delphi寫...請各位前輩幫幫忙... 雖然還沒成功,但我想這種方式似乎蠻實用的,直接在交易時, ShowMessage而不是在前端判斷,可以減少麻煩,統一設計方法 且不會造成資料流錯誤...不知我的想法可不可行???????????????????? Creating Extended Stored Procedures An extended stored procedure is a function with a prototype: SRVRETCODE xp_extendedProcName (SRVPROC *); Using the prefix "xp_" is optional. Extended stored procedure names are case sensitive when referenced in Transact-SQL statements, regardless of code page/sort order installed on the server. An extended stored procedure is implemented in a 32-bit dynamic-linked library (DLL). When you build a DLL: If an entry point is necessary, write a DllMain function. This function is optional; if you do not provide it in source code, the compiler links its own version, which does nothing but return TRUE. If you provide a DllMain function, the operating system calls this function when a thread or process attaches to or detaches from the DLL. All functions called from outside the DLL (all extended stored procedure functions) must be exported. You can export a function by listing its name in the EXPORTS section of a .def file, or you can prefix the function name in the source code with __declspec(dllexport), a Microsoft compiler extension (Note that __declspec() begins with two underscores). These Open Data Services files are required for creating an extended stored procedure DLL. File Description Srv.h Open Data Services header file Opends60.lib Import library for Opends60.dll It is highly recommended that all Microsoft® SQL Server™ 2000 extended stored procedure DLLs implement and export the following function: __declspec(dllexport) ULONG __GetXpVersion() { return ODS_VERSION; } When SQL Server loads an extended stored procedure DLL, SQL Server checks for the above function. Note __declspec(dllexport) is a Microsoft-specific compiler extension. If your compiler does not support this directive, you should export this function in your DEF file under the EXPORTS section. When SQL Server is started with the trace flag -T260 or if a user with system administrator privileges runs DBCC TRACEON (260), then if the extended stored procedure DLL does not support __GetXpVersion(), a warning message (Error 8131: Extended stored procedure DLL '%' does not export __GetXpVersion().) is printed to the error log (Note that __GetXpVersion() begins with two underscores). If you get this message, and you are running an extended stored procedure DLL compiled with headers and libraries from SQL Server version 6.x, refer to Level 1: Handling Discontinued Functionality. If you get this message and are running an extended stored procedure DLL compiled with headers and libraries from SQL Server 7.0, your extended stored procedure DLL is not exporting the function __GetXpVersion(). If the extended stored procedure DLL exports __GetXpVersion(), but the version returned by the function is less than that required by the server, a warning message (Error 8132: Extended stored procedure DLL '%' reports its version is %d.%d. Server expects version %d.%d.) stating the version returned by the function and the version expected by the server is printed to the error log. If you get this message, you are returning an incorrect value from __GetXpVersion(), or you are compiling with an older version of srv.h. Note SetErrorMode, a Microsoft Win32® function, should not be called in extended stored procedures. For more information about creating a DLL, see the development environment documentation and the Microsoft Win32 SDK documentation. To create an extended stored procedure DLL by using Microsoft Visual C Create a new project of type Win32 Dynamic Link Library. Set the directory for include files and library files to C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Include and C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Lib, respectively. On the Tools menu, click Options. In the Options dialog box, click the Directories tab and set the directory for include files and library files. On the Project menu, click Settings. In the Project Settings dialog box, click the Link tab. Click the General category, and then add opends60.lib to object/library modules. Add source files (.c, .cpp, and .rc files, and so on) to your project.
------
//------------------------------------------------
我常在想,寫程式跟爬格子到底有什麼不同呢???????????
//------------------------------------------------
系統時間:2024-04-18 11:52:22
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!