Click to See Complete Forum and Search --> : Retrieve result set from DLL


simmu
February 4th, 2009, 05:29 PM
Im using Win32 API(Ex:CreateWindow,GetWindowText,SetWindowText)Im not using MFC .Im using SQL(ODBC Connectivity) for database. I have a DLL which connects to database and DLL has a function SearchString. This function takes string as an input searches for the string in the records in the database and displays all the records that matches the input string. When I use this DLL from my application, how do I retrieve result set in my application?

0xC0000005
February 7th, 2009, 02:51 PM
DLLs have an interface specification. In other words, a list of exported functions available for use by client applications and documentation on how to use the functions. SearchString() is obviously an example of one of those functions. Without seeing the interface specification and documentation for the DLL, no one will be able to answer your question. Can you provide more information?

simmu
February 10th, 2009, 03:14 PM
No it not one of those exported functions of DLL. It's just an simple function user defined function which connects to the database and execute SQL statement.

SQLRETURN SearchContact(LPTSTR szSearchString)
{
SQLINTEGER cbValue = SQL_NTS;
SQLINTEGER cbFName,cbLName,cbContactNo,cbAddress,cbDOB;
SQLCHAR szFirstName[30],szLastName[30],szContactNo[30],szAddress[30],szDOB[30];
sqlRetVal = CreateConnection();

sqlRetVal = SQLAllocHandle(SQL_HANDLE_STMT, g_hdlConn, &g_hdlStmt);
sqlRetVal = SQLBindParameter(g_hdlStmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_VARCHAR,30,0,szSearchString,0,&cbValue);
sqlRetVal = SQLPrepare(g_hdlStmt, (SQLCHAR*)"SELECT * FROM Contacts WHERE FirstName = ?", SQL_NTS);
sqlRetVal = SQLExecute(g_hdlStmt);

while(SQLFetch(g_hdlStmt) == SQL_SUCCESS)
{
SQLGetData(g_hdlStmt,1,SQL_C_CHAR,szFirstName,30,&cbFName);
SQLGetData(g_hdlStmt,2,SQL_C_CHAR,szLastName,30,&cbLName);
SQLGetData(g_hdlStmt,3,SQL_C_CHAR,szContactNo,30,&cbContactNo);
SQLGetData(g_hdlStmt,4,SQL_C_CHAR,szAddress,30,&cbAddress);
SQLGetData(g_hdlStmt,5,SQL_C_CHAR,szDOB,30,&cbDOB);
cout << endl;
_tprintf("%-12s %-12s %-16s %-12s %-12s",szFirstName,szLastName,szContactNo,szAddress,szDOB);
cout << endl;
}
DeleteConnection();
return sqlRetVal;
}

I am exporting this above DLL function and importing it in my application. How to get the result set of the above DLL function in my application.

Igor Vartanov
February 19th, 2009, 05:16 AM
You have to modify the dll. ;)

Provide some container for returned information and replace this
_tprintf("%-12s %-12s %-16s %-12s %-12s",szFirstName,szLastName,szContactNo,szAddress,szDOB);for stuffing it with the information you need.