Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

calling c/c++ dll code form sql

  • 01-03-2002 2:37pm
    #1
    Closed Accounts Posts: 5,564 ✭✭✭


    #include "C:\xpKBS\xp_KBS.h"
    #include <windows.h>
    #include <stdio.h>
    
    int
    DllClassBase::virtual_method () const
    {
      return -1;
    }
    
    int xpkbs(char*string,char*filename)
    {
     FILE*file;
     int a;
     file=fopen(filename,"a+");
     a=fwrite(string,strlen(string),1,file);
     fclose(file);
     if(a<=0)
      return -1;
    return 0 ;
    };
    
    BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason,
                           LPVOID reserved /* Not used. */ );
    
    /* DllMain Results:
           TRUE on success, FALSE on failure.  */
    
    BOOL APIENTRY
    DllMain (
    	 HINSTANCE hInst        /* Library instance handle. */ ,
    	 DWORD reason           /* Reason this function is being called. */ ,
    	 LPVOID reserved        /* Not used. */ )
    {
    
      switch (reason)
        {
        case DLL_PROCESS_ATTACH:
          break;
    
        case DLL_PROCESS_DETACH:
          break;
    
        case DLL_THREAD_ATTACH:
          break;
    
        case DLL_THREAD_DETACH:
          break;
        }
      return TRUE;
    }
    
    USE master
    
    EXEC sp_dropextendedproc xpkbs
    EXEC sp_addextendedproc xpkbs, 'sqltodisk.dll'
    
      
    exec xpkbs 'This is My Data','g:\test.txt'
    

    For some reason sql is not finding the function referenced as xpkbs?
    Error==:
    Cannot find function xkbs in the library


Comments

  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    You have to include
    Srv.h
    and link in
    Opends60.lib

    check out
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odssql/ods_6_con_00_6p9v.asp

    kayos


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    hmm thanks for that kayos... doesn't look as if the pretinant lib has been ported to mingw so I guess I will have to install Vc++.


  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    Ahhh the joys of M$ :) One thing be very very careful with xp's as if you dont handle every last possible error you could (I've seen it happen) bring down the SQL server.

    If you just want to pump a result set to a file you could use xp_cmdshell and use osql to connect run your query and pipe the results to a file if you have sql server installed on your machine just type osql /? at the command promt.

    kayos


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    Yeah I would have thought that there would be some easier way of printing to a text file in sql, but apparently it is not too easy (our sql guys don't seem to think it is easy anyhoo) so if I can get extended sps working against a dll then we would (probably/possibly) be looking at moving an entire printing routine to dll serverside code or at leat (I could have fun wriitng it)

    Cuidado con el gato!


  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    try this
    osql -S<servername> -d<dbname> -E -Q"<insert query here>" -o<outputfilename>
    

    that will pump out the results to a file for you. You could call that by using xp_cmdshell like this
    xp_cmdshell 'osql -S<servername> -d<dbname> -E -Q"<insert query here>" -o<outputfilename>'
    

    you should be able to do what you want without having to write a xp yourself. Or if you want to be really fancy you could use DTS which is damn handy.

    kayos


  • Advertisement
  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    http://www.tair.freeservers.com/cpp/xp_Works.html

    In case anyone is looking for some good resources on writing a serverside extended stored procedure for sql in a dll, you might want to check out this.


Advertisement