Solved

SQL Server / Client Network libraries

Posted on 2000-05-03
5
214 Views
Last Modified: 2013-12-03
Hi,
I wanted to know if anyone can get me a url of a sample C/S Net-Library DLL implementation or at least a header file.

0
Comment
Question by:arbitrary
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:NickRepin
ID: 2776042
server side is done
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 2000 total points
ID: 2776481
Here are the fully commented headers.

If you increase the points for hurry (as you promised), I'll give you the two sample programs as well.
These programs demonstrate the usage of API. One of them loads the server-side net library, the other one loads the client-side library.
Then they connect to each other and exchange some data.

With my answer, you can write your own C/S net libraries and then sell them for million dollars.
All you have to do is to implement the net library API.
It is easy...

#include <windows.h>

//-----------------------------------------
// Client.h
// Client Net-library
//-----------------------------------------
// NOTE: xxxW functions are just the thunks for the appropriate
// xxx functions. For example, ConnectionErrorW() is the UNICODE version
// of the ConnectionError()
//-----------------------------------------


//
// Returns the numeric codes and the text description of the last error.
// ConnectionErrorW() is the UNICODE thunk for the ConnectionError().
//
typedef BOOL (__cdecl *ConnectionErrorT) (
   PVOID  IN  hConn,       // Pointer to the connection object.
   PDWORD OUT pdwError1,   // Last error code.
   LPSTR* OUT ppszError,   // Pointer-to-pointer to the error description.
   PDWORD OUT pdwError2    
);

//
// Returns the version of the Net Library.
//
typedef DWORD (__cdecl *ConnectionVerT)();

//
// Returns the required size of the connection object.
//
typedef DWORD (__cdecl *ConnectionObjectSizeT)();

//
// Closes the connection.
//
typedef BOOL (__cdecl *ConnectionCloseT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Creates the connection object.
//
typedef BOOL (__cdecl *ConnectionOpenT)(
   PVOID  OUT hConn,          // Pointer to the connection object.
   LPCSTR IN  PipeName,       // Server name.
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Writes data.
//
// Returns: Number of bytes written or zero if error.
//
typedef DWORD (__cdecl *ConnectionWriteT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  IN  pBuffer,        // Points to buffer that contains data.
   DWORD  IN  nNumberOfBytesToWrite,
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Reads data.
//
// Returns the number of bytes read or zero if error.
// If timeout, then *pdwErrCode=DWORD(-2)
//
typedef DWORD (__cdecl *ConnectionReadT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  OUT pBuffer,        // Points to buffer that receives data.
   DWORD  IN  nNumberOfBytesToRead0,  // Must be <= nNumberOfBytesToRead, not used
   DWORD  IN  nNumberOfBytesToRead, // Actually used in ReadFile
   DWORD  IN  SecondsToWait,    // 0 if wait forever
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Writes Out-of-band (urgent) data.
//
// Returns: Number of bytes written or zero if error.
//
typedef DWORD (__cdecl *ConnectionWriteOOBT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  IN  pBuffer,        // Points to buffer that contains data.
   DWORD  IN  nNumberOfBytesToWrite,
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Returns connection status.
// Not implemented for named pipes - returns 0, *pdwErrCode=0.
// Not implemented for tcp/ip   - returns only 0.
//
typedef DWORD (__cdecl *ConnectionStatusT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  unknown,        
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Sets connection mode.
// Not implemented for tcp/ip   - does nothing.
// For named pipes:
//   if dwMode==1  - stores 1 into internal variable.
//   else if dwMode==0  - stores 0 into internal variable.
//   else does nothing.
//   ANYWAY, this internal variable is not used.
//
typedef VOID (__cdecl *ConnectionModeT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   DWORD  IN  dwMode
);

//
// Returns TRUE if there is a data to read, number of bytes is stored
// into pTotalBytesAvail.
//
typedef BOOL (__cdecl *ConnectionCheckForDataT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PDWORD pTotalBytesAvail,
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Writes, then reads data in one operation.
//
// Returns: Number of bytes read or zero if error.
// If timeout, then *pdwErrCode=DWORD(-2)
//
typedef DWORD (__cdecl *ConnectionTransactT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  OUT pBufRead,       // Points to buffer that receives data.
   PVOID  IN  pBufWrite,      // Points to buffer that contains data to write.
   DWORD  IN  nNumberOfBytesToWrite,
   DWORD  IN  nNumberOfBytesToRead0,  // Must be <= nNumberOfBytesToRead, not used
   DWORD  IN  nNumberOfBytesToRead, // Actually used in ReadFile
   DWORD  IN  SecondsToWait,    // 0 if wait forever
   PDWORD OUT pdwErrCode      // Last error code.
);


//
// Enumerates the servers.
// Actually, I decided to not waste my time on it, because I'm sure
// you don't need it.
// It seems it returns the zero-separated list of servers, the list is
// terminated by the additional zero.
// It is implemented for named pipes, and uses NetServerEnum() API.
// It is not implemented for tcp/ip, and acts as follows:
//    if(pBuffer) *LPWORD(pBuffer)=0;
//    return 2;
//
typedef DWORD (__cdecl *ConnectionServerEnumT)(
   PVOID  unknown1,
   PVOID  unknown2,
   LPWORD OUT pBuffer      // At least, must contain two bytes.
);

//-----------------------------------------
// Server.h
// Server Net-library
//-----------------------------------------

//
// Returns the numeric codes and the text description of the last error.
//
typedef BOOL (__cdecl *ConnectionErrorT) (
   PVOID  IN  hConn,       // Pointer to the connection object.
   PDWORD OUT pdwError1,   // Last error code.
   LPSTR* OUT ppszError,   // Pointer-to-pointer to the error description.
   PDWORD OUT pdwError2    // If pdwError2==11, then ppszError must be freed
                           // by LocalFree().
);

//
// Returns the version of the Net Library.
//
typedef DWORD (__cdecl *ConnectionVerT)();

//
// Returns the required size of the connection object.
//
typedef DWORD (__cdecl *ConnectionObjectSizeT)();

//
// Closes the connection.
//
typedef BOOL (__cdecl *ConnectionCloseT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Associates the connection object with the existing completion port
// (if *phCompletionPort!=0), or with a new completion port
// (if *phCompletionPort==0; on return it will contain the handle
// of the new completion port).
//
// May return TRUE with the pdwErrCode!=0. This may happen if
// CreateIoCompletionPort returned 0, and GetLastError() returned
// ERROR_IO_PENDING.
//
typedef BOOL (__cdecl *ConnectionInitAsyncT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PHANDLE IN OUT phCompletionPort, // Points to the existing completion
                              // port or to 0, on return contains the handle
                              // of the new completion port.
   DWORD IN CompletionKey,    // See CreateIoCompletionPort.
   DWORD IN NumberOfConcurrentThreads, // See CreateIoCompletionPort.
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Reads data.
//
// May return TRUE with the pdwErrCode==ERROR_IO_PENDING.
//
typedef BOOL (__cdecl *ConnectionReadAsyncT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  OUT pBuffer,        // Points to buffer that receives data.
   DWORD  IN  nNumberOfBytesToRead0,  // Must be <= nNumberOfBytesToRead, not used
   DWORD  IN  nNumberOfBytesToRead, // Actually used in ReadFile
   LPOVERLAPPED IN lpOverlapped,    
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Writes data. Uses the internal OVERLAPPED structure.
//
// Returns:
//   0 if success (WriteFile returned TRUE).
//   1, if pdwErrCode==ERROR_IO_PENDING, pNumberOfBytesWritten=0
//   2, if other error occurred.
//
typedef DWORD (__cdecl *ConnectionWriteAsyncT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  IN  pBuffer,        // Points to buffer that contains data.
   DWORD  IN  nNumberOfBytesToWrite,
   PDWORD OUT  pNumberOfBytesWritten,
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Alertable waits for the write operation to complete.
//
// Returns:
//   0 if success (pNumberOfBytesWritten contains result).
//   1, timeout (still ERROR_IO_PENDING), pNumberOfBytesWritten=0
//   2, if other error occurred.
//
typedef DWORD (__cdecl *ConnectionWriteStatusT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   DWORD  IN  dwMilliseconds, // See WaitForSingleObjectEx
   PDWORD OUT pNumberOfBytesWritten,
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Writes data.
//
// Returns: Number of bytes written or zero if error.
//
typedef DWORD (__cdecl *ConnectionWriteT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  IN  pBuffer,        // Points to buffer that contains data.
   DWORD  IN  nNumberOfBytesToWrite,
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Reads data.
//
// Returns the number of bytes read or zero if error.
// If timeout, then *pdwErrCode=DWORD(-2)
//
typedef DWORD (__cdecl *ConnectionReadT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  OUT pBuffer,        // Points to buffer that receives data.
   DWORD  IN  nNumberOfBytesToRead0,  // Must be <= nNumberOfBytesToRead, not used
   DWORD  IN  nNumberOfBytesToRead, // Actually used in ReadFile
   WORD   IN  SecondsToWait,    // 0 if wait forever
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Peeks (doesn't remove it from the net) data.
//
// Returns the number of bytes read or zero if error.
// If timeout, then *pdwErrCode=DWORD(-2)
//
typedef DWORD (__cdecl *ConnectionPeekT)(
   PVOID  IN  hConn,          // Pointer to the connection object.
   PVOID  OUT pBuffer,        // Points to buffer that receives data.
   DWORD  IN  szBuf,          // Must be <= nNumberOfBytesToRead
   DWORD  IN  nNumberOfBytesToRead, // NOT used
   WORD   IN  SecondsToWait,    // 0 if wait forever, FFFFF if return immediately
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Creates the connection object.
//
typedef BOOL (__cdecl *ConnectionListenT)(
   PVOID  OUT hConn,          // Pointer to the connection object.
   LPCSTR IN  PipeName,       // Pipe name "[name][,bufsize]".
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// Actually creates the connection (named pipe).
// If succeeded, returns TRUE and the hNewConn which must be used
// in Read/Write operations.
//
typedef BOOL (__cdecl *ConnectionAcceptT)(
   PVOID  IN  hConn,          // Pointer to the source connection object,
                              // created by ConnectionListen.
   PVOID  OUT  hNewConn,      // Pointer to the new connection object,
                              // which is connected to the client.
   HANDLE IN  hEvent,         // Event object, which will be used in
                              // the overlapped read operations.
   PDWORD OUT pdwErrCode      // Last error code.
);

//
// OPTIONAL (doesn't exist for named pipes).
// Used to pass the registry key name to the Net Libarary.
// The key is used to store misc parameters.
// Default value for TCP/IP Net Library is
// SOFTWARE\Microsoft\MSSQLServer\MSSQLServer
//
typedef VOID (__cdecl *ConnectionRegistryT)(
   LPCSTR IN  pszKeyName
);
0
 
LVL 1

Author Comment

by:arbitrary
ID: 2785748
ok ,
that looks good.
i'll try it and let u know
0
 
LVL 1

Author Comment

by:arbitrary
ID: 2789549
if you send the samples to me (yanoshka@email.com)
i'll give you 200 points ,
with another A.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2790309
Sent

I'm waiting for the question in the Windows Programming area...

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now