Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, After many hours of Googling, I successfully compiled a DLL to add as a SQL Server 2000 extended stored procedure. I'm going to share it here, since it's just a compilation of things I've put together from my Googling. (I used Visual Studio 2010). I'm not going to post everything - I started by creating a new project in Visual Studio and choosing Win32 Console Application, then Next, then DLL. It creates a few header files and other files for you. Some of them I didn't see any need for. And some of the header files you must add to the project manually. But here's my main .cpp code:</p> <pre><code>#include "stdafx.h" #include "srv.h" //Must get from C:\Program Files (x86)\Microsoft SQL Server\80\Tools\DevTools\Include #include "shellapi.h" //need for ShellExecute #include "string" //needed for std:string #include &lt;sys/stat.h&gt; //need for stat in fileExists function below #define DLL_FUNC extern "C" __declspec (dllexport) __declspec(dllexport) ULONG __GetXpVersion() { return ODS_VERSION; } bool fileExists(const std::string&amp; filename) { struct stat buf; if (stat(filename.c_str(), &amp;buf) != -1) { return true; } return false; } DLL_FUNC int __stdcall RunPP() { if (fileExists("C:\\FileOnServer\\execute.bat")) { ShellExecute(NULL,TEXT("open"), TEXT("C:\\FileOnServer\\execute.bat"), NULL, NULL,SW_SHOWNORMAL); return 0; } else { MessageBox(HWND_DESKTOP, TEXT("File not found."), TEXT("Message"), MB_OK); return 1; } } </code></pre> <p>I learned that you can test out this DLL using rundll32 (<code>rundll32 yourdllname.dll,functionname</code> {no space after comma}) from the command line, but only if you include a .def file in your project. My def file is</p> <pre><code>LIBRARY EXPORTS RunPP </code></pre> <p>Also, as the <a href="http://msdn.microsoft.com/en-us/library/aa215790%28v=sql.80%29.aspx" rel="nofollow">documentation</a> states, I tried to add a reference to Opends60.lib in Project > Properties... > Linker > Input > Additional Dependencies, but it looks like it got removed at some point.</p> <p>For those of you as newbie as I am, I had to learn a lot of things in the project's Property pages like switching C/C++ > Code Generation > Runtime Library to /MD. Also learning how to compile in Release mode, where to locate the resulting .dll file, etc.</p> <p>Then when moving the compiled DLL to my SQL Server machine (Win2003R2), I had to install the VC++ 2010 Redistributable for it to run. Then I copied the DLL to C:\Program Files\Microsoft SQL Server\MSSQL\Binn on my machine (same place where xp_cmdShell extended stored procedure's DLL was), and then ran sp_addextendedproc according to the documentation to register it as an available extended stored procedure in the master database. Then granting privileges for users to execute it, etc.</p> <p>I know all this is an old technology. I should just upgrade my SQL Server version. But maybe this will help someone else.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload