通过把winvnc 和vncviewer 打包成dll,以供其他程序使用, 然后在dll 里面添加自己调用的函数和修改vnc里面的参数等
winvnc 项目里的调用函数 :在 vncconndialog.cpp 这个文件里面
extern "C" _declspec(dllexport) BOOL test(char* hostchar,char* IDchar)
{
//vncConnDialog *_this = helper::SafeGetWindowUserData<vncConnDialog>(hwnd);
char hostname[_MAX_PATH];
char actualhostname[_MAX_PATH];
char idcode[_MAX_PATH];
char *portp;
int port;
bool id;
strcpy(hostname, hostchar);
strcpy(idcode, IDchar);
/*size_t i;
for (i=0;i<strlen(IDchar);i++)
{
idcode[i]=IDchar[i];
}*/
/*size_t j;
for (j=0;j<strlen(hostchar);j++)
{
hostname[j]=hostchar[j];
}*/
// Get the hostname of the VNCviewer
//GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, hostname, _MAX_PATH);
//GetDlgItemText(hwnd, IDC_IDCODE, idcode, _MAX_PATH);
if (strcmp(idcode,"")==0) id=false;
else id=true;
//adzm 2010-02-15 - Multiple repeaters chosen by modulo of ID
strcpy(actualhostname, hostname);
char finalidcode[_MAX_PATH];
//adzm 2010-08 - this was sending uninitialized data over the wire
ZeroMemory(finalidcode, sizeof(finalidcode));
if (id) {
size_t i = 0;
for (i = 0; i < strlen(idcode); i++)
{
finalidcode[i] = toupper(idcode[i]);
}
finalidcode[i] = 0;
if (0 != strncmp("ID:", idcode, 3)) {
strcpy(finalidcode, "ID:");
for (i = 0; i < strlen(idcode); i++)
{
finalidcode[i+3] = toupper(idcode[i]);
}
finalidcode[i+3] = 0;
}
//adzm 2010-02-15 - At this point, finalidcode is of the form "ID:#####"
int numericId = atoi(finalidcode + 3);
int numberOfHosts = 1;
for (i = 0; i < strlen(hostname); i++) {
if (hostname[i] == ';') {
numberOfHosts++;
}
}
if (numberOfHosts <= 1) {
// then hostname == actualhostname
} else {
int modulo = numericId % numberOfHosts;
char* szToken = strtok(hostname, ";");
while (szToken) {
if (modulo == 0) {
strcpy(actualhostname, szToken);
break;
}
modulo--;
szToken = strtok(NULL, ";");
}
}
}
// Calculate the Display and Port offset.
port = INCOMING_PORT_OFFSET;
portp = strchr(actualhostname, ':');
if (portp)
{
*portp++ = '\0';
if (*portp == ':') // Tight127 method
{
port = atoi(++portp); // Port number after "::"
}
else // RealVNC method
{
if (atoi(portp) < 100) // If < 100 after ":" -> display number
port += atoi(portp);
else
port = atoi(portp); // If > 100 after ":" -> Port number
}
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (!tmpsock) {
return TRUE;
}
// Connect out to the specified host on the VNCviewer listen port
// To be really good, we should allow a display number here but
// for now we'll just assume we're connecting to display zero
tmpsock->Create();
if (tmpsock->Connect(actualhostname, port))
{
vncServer *testServer=new vncServer();
if (id)
{
tmpsock->Send(finalidcode,250);
tmpsock->SetTimeout(0);
/* if (strncmp(hostname,"ID",2)!=0)
{
while (true)
{
char result[1];
tmpsock->Read(result,1);
if (strcmp(result,"2")==0)
break;
tmpsock->Send("1",1);
}
}*/
// adzm 2009-07-05 - repeater IDs
// Add the new client to this server
// adzm 2009-08-02
testServer->AddClient(tmpsock, TRUE, TRUE, 0, NULL, finalidcode, actualhostname, port);
//_this->m_server->AddClient(tmpsock, TRUE, TRUE, 0, NULL, finalidcode, actualhostname, port);
} else {
// Add the new client to this server
// adzm 2009-08-02
testServer->AddClient(tmpsock, TRUE, TRUE, 0, NULL, NULL, actualhostname, port);
}
// And close the dialog
}
else
{
// Print up an error message
MessageBoxSecure(NULL,
sz_ID_FAILED_CONNECT_LISTING_VIEW,
sz_ID_OUTGOING_CONNECTION,
MB_OK | MB_ICONEXCLAMATION );
delete tmpsock;
}
return TRUE;
}