I would like to test extended stored procedure (I know that they are now deprecated, but from personal reason I would like to test them).
I have generate a dll file in VC++ and here is my code:
//First.h
#include<iostream>
#include<srv.h>
using namespace std;
RETCODE _declspec(dllexport) xp_firstfun(SRV_PROC *srvproc);
and
//main.cpp
#include<iostream>
#include "First.h"
using namespace std;
RETCODE xp_firstfun(SRV_PROC *srvproc)
{
cout<<"Hello World froom DLL"<< endl;
cin.get();
return 0;
}
I can successfully add this dll to database with this command:
sp_addextendedproc 'xp_firstfun', 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Binn\FirstDLL.dll'
but if I try to execute the function:
exec xp_firstfun
I am facing to this error:
Could not find the function xp_firstfun in the library C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Binn\FirstDLL. Reason: 127(procedure is not found).
I have two questions:
thank you for your helps
change your declaration. This may help you as in c++ the function name gets modified during compilation as part of name mangling.
extern "C"
{
RETCODE _declspec(dllexport) xp_firstfun(SRV_PROC *srvproc);
}