不用VC,直接用asp加存储过程就可以搞定
http://community.csdn.net/Expert/topic/3960/3960021.xml?temp=.49844

解决方案 »

  1.   

    extended proc + ASP
    #include "stdafx.h"
    #define DBNTWIN32
    #include <windows.h>
    //G:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Include\sqlfront.h
    #include <sqlfront.h>
    #include <sqldb.h>
    #include <srv.h>
    #include <sstream>
    #include <UrlMon.h>
    #pragma comment(lib,"urlmon.lib")
    #define XP_NOERROR                      0
    #define XP_ERROR                        1
    #define MAX_BINDTOKEN                   256
    #define MAX_SERVER_ERROR 20000
    #define XP_HELLO_ERROR MAX_SERVER_ERROR+1
    //G:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Lib\opends60.lib
    //G:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Lib\ntwdblib.lib
    #pragma comment(lib,"opends60.lib")
    #pragma comment(lib,"Ntwdblib.lib")
    //need to download the following dlls
    //G:\Program Files\Microsoft SQL Server\80\Tools\Binn\OPENDS60.DLL
    //G:\Program Files\Microsoft SQL Server\80\Tools\Binn\ums.DLL
    extern "C" __declspec(dllexport) ULONG WINAPI __GetXpVersion()
    {
    return ODS_VERSION;
    }
    extern "C" __declspec(dllexport) BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
     )
    {
        return TRUE;
    }
    // send XP usage info to client
    void printUsage (SRV_PROC *pSrvProc)
    {
    // usage: exec xp_call_asp_by_onega <@table_name input> <@record_id input> <@additional_info input>
    // Example:
    // exec xp_call_asp_by_onega 'table1',1,'for table1'
    //build by Onega at 2005/04/23 with VC2003, Windows 2003, SQLServer 2000
    srv_sendmsg(pSrvProc, SRV_MSG_ERROR, XP_HELLO_ERROR, SRV_INFO, 1,
    NULL, 0, (DBUSMALLINT) __LINE__, 
    "Usage: exec xp_call_asp_by_onega <@table_name input> <@record_id input> <@additional_info input>",
    SRV_NULLTERM);
    srv_senddone(pSrvProc, (SRV_DONE_ERROR | SRV_DONE_MORE), 0, 0);
    }// send szErrorMsg to client
    void printError (SRV_PROC *pSrvProc, CHAR* szErrorMsg)
    {
    srv_sendmsg(pSrvProc, SRV_MSG_ERROR, XP_HELLO_ERROR, SRV_INFO, 1,
    NULL, 0, (DBUSMALLINT) __LINE__, 
    szErrorMsg,
    SRV_NULLTERM); srv_senddone(pSrvProc, (SRV_DONE_ERROR | SRV_DONE_MORE), 0, 0);
    }extern "C" __declspec(dllexport) SRVRETCODE WINAPI xp_call_asp_by_onega(SRV_PROC* pSrvProc)
    {
    BYTE        bType;
    long        cbMaxLen;
    long        cbActualLen;
    BOOL        fNull;
    // Count up the number of input parameters.
    //http://community.csdn.net/Expert/TopicView3.asp?id=3960017
    //table_name string,record_id int,additional_info string
    if (srv_rpcparams(pSrvProc) != 3)
    {
    printUsage(pSrvProc);
    return (XP_ERROR);
    } // Use srv_paraminfo to get data type and length information.
    int parameter_index = 1;
    if (srv_paraminfo(pSrvProc, parameter_index, &bType, (ULONG*)&cbMaxLen, (ULONG*)&cbActualLen,
    NULL, &fNull) == FAIL)
    {
    printError (pSrvProc, "srv_paraminfo failed...");
    return (XP_ERROR);    
    }
    // Make sure the parameter is of char or varchar datatype
    if (bType != SRVBIGVARCHAR && bType != SRVBIGCHAR)
    {
    printUsage(pSrvProc);
    return (XP_ERROR);    
    }
    char szTable[128];
    memset(szTable,0,sizeof(szTable));
    memcpy(szTable, srv_paramdata(pSrvProc, parameter_index), srv_paramlen(pSrvProc, parameter_index));
    parameter_index = 2; int record_id = 0;
    memcpy(&record_id, srv_paramdata(pSrvProc, parameter_index), 
    srv_paramlen(pSrvProc, parameter_index));
    parameter_index = 3;
    if (srv_paraminfo(pSrvProc, parameter_index, &bType, (ULONG*)&cbMaxLen, 
    (ULONG*)&cbActualLen,
    NULL, &fNull) == FAIL)
    {
    printError (pSrvProc, "srv_paraminfo failed...");
    return (XP_ERROR);    
    }
    // Make sure the parameter is of char or varchar datatype
    if (bType != SRVBIGVARCHAR && bType != SRVBIGCHAR)
    {
    printUsage(pSrvProc);
    return (XP_ERROR);    
    } char szAdditionalInfo[128];
    memset(szAdditionalInfo,0,sizeof(szAdditionalInfo));
    memcpy(szAdditionalInfo, srv_paramdata(pSrvProc, parameter_index), 
    srv_paramlen(pSrvProc, parameter_index));
    //check received parameter:
    std::stringstream ss;
    ss<<"xp_call_asp_by_onega('"<<szTable<<"',"<<record_id<<",'"<<szAdditionalInfo<<"')";
    OutputDebugString(ss.str().c_str());
    ss.str("");
    ss<<"http://127.0.0.1/xp_call_asp_by_onega.asp?table_name="<<szTable<<"&record_id="
    <<record_id<<"&additional_info="
    <<szAdditionalInfo;
    LPCTSTR download_file_name = "c:\\xp_call_asp_by_onega.htm";
    DeleteFile(download_file_name);
    URLDownloadToFile(NULL,ss.str().c_str(),download_file_name,0,NULL);
    OutputDebugString(ss.str().c_str());
    srv_senddone(pSrvProc, (SRV_DONE_COUNT | SRV_DONE_MORE), 0, 1);
    return (XP_NOERROR);
    }/*
    //def file
    LIBRARY extended_proc_call_asp
    EXPORTS
    xp_call_asp_by_onega
    __GetXpVersion
    */
    /*
    --install to G:\Program Files\Microsoft SQL Server\80\Tools\Binn\extended_proc_call_asp.dll
    --sp_addextendedproc 'xp_call_asp_by_onega', 'extended_proc_call_asp.dll'
    exec xp_call_asp_by_onega 'table2', 2, 'exec xp test'
    --sp_dropextendedproc 'xp_call_asp_by_onega'
    */
    /*  xp_call_asp_by_onega.asp
    <%
    table_name = request.querystring("table_name")
    record_id = request.querystring("record_id")
    additional_info = request.querystring("additional_info")
    if len(table_name)>0 AND len(additional_info)>0 then
    application(table_name & cstr(record_id) ) = table_name & "," _
    & CStr(record_id) & "," & additional_info
    end if
    for each x in Application.Contents
    Response.Write(x & "=" & Application.Contents(x) & "<br />")
    next%>
    */