|
A given host can have more than one address.
Here's a simple IP v4 example:
char hostname[256];
if (0 == ::gethostname(hostname, sizeof(hostname)))
{
addrinfo aihints;
addrinfo *ailist = NULL;
memset(&aihints, 0, sizeof(aihints));
aihints.ai_family = AF_INET;
aihints.ai_socktype = SOCK_STREAM;
aihints.ai_protocol = IPPROTO_TCP;
if (::getaddrinfo(hostname, NULL, &aihints, &ailist) == 0)
{
addrinfo *paddrinfo = ailist;
while (paddrinfo)
{
sockaddr_in *paddr_in = (sockaddr_in *)paddrinfo->ai_addr;
char *pipstring = inet_ntoa(paddr_in->sin_addr);
paddrinfo = paddrinfo->ai_next;
}
::freeaddrinfo(ailist);
}
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Try to understand this. I have a main application and a dll. main application has its mfc view window, say window 1 and there's a button on main window(window 1) which calls a function inside a dll to open a new window, say window 2. Both view windows handles WM_KEYDOWN message and pop up a message box.
Now, when only window 1 is opened, all keyboard messages are properly received by it.
When I open a window 2 and then press key, no keyboard message is received by either of the windows.
Even if I minimize window 1 by clicking on minimize button at top right, no keyboard message is received by either of the windows.
Imagine this -> both windows are open side by side and if I directly click on window 2, then it will bring window 2 to forefront and now window 2 will receive all keyboard messages.
I know window 2 is child of window 1 but somehow not able to route messages to window 2 properly. Does anyone have any idea why this problem in setting focus to window 2 is occuring. when I minimize window 1, why cant window 2 receive keyboard messages???
the fruits of your success will be in direct ratio to the honesty and sincerity of your own efforts in keeping your own records, doing your own thinking and, reaching your own conclusions.
..surviving in autumn..in love with spring..
|
|
|
|
|
Hello People,
i have a code written in C++ for DDE ... my task is to read data from a EXCEL sheet at a regular interval ... i am able to do it with the following code ... but the problem is when i say A16,B67,Z63 etc.. my application gives me request fail and type some of my code to excel sheet i don't know how ... but yes when i say A1, B9, V2 etc i.e alphabet with a single digit it gives me correct answer .. but also when i hard-code A16 as "R16C1" it gives me correct answer ... the hard-coded string is the form in which excel understands .... so i have a function to convert C16,A1 to R16C3, R1C1 ...
please help me with it ... and also how to read data from different sheets from a single EXCEL ...
hoping for a positive and immediate reply ... !!
Thank you in advance
Code Build: VC++ 6.0
File Name: DDE_ExcelApplication.
Code:-
// cppDdeApplication.cpp : Defines the entry point for the console application.
//
# include "stdafx.h"
# include "windows.h"
# include "ddeml.h"
# include "stdio.h"
# include "string.h"
# include "conio.h"
HDDEDATA CALLBACK DdeCallback
(
UINT uType, // Transaction type.
UINT uFmt, // Clipboard data format.
HCONV hconv, // Handle to the conversation.
HSZ hsz1, // Handle to a string.
HSZ hsz2, // Handle to a string.
HDDEDATA hdata, // Handle to a global memory object.
DWORD dwData1, // Transaction-specific data.
DWORD dwData2) // Transaction-specific data.
{/* This function is called in DdeInitialize() */
return 0;
}
void DDEExecute(DWORD idInst, HCONV hConv, char* szCommand)
{
//HDDEDATA hData = DdeCreateDataHandle(DWORD(idInst), (LPBYTE)szCommand,DWORD(szCommand)+1, 0, NULL, CF_TEXT, 0);
HDDEDATA hData = DdeCreateDataHandle(DWORD(idInst), (LPBYTE)szCommand,1, 0, NULL, CF_TEXT, 0);
if (hData==NULL)
{
printf("Command failed: %s\n", szCommand);
}
else
{
DdeClientTransaction((LPBYTE)hData, 0xFFFFFFFF, hConv, 0L, 0,XTYP_EXECUTE, TIMEOUT_ASYNC, NULL);
}
}
void DDERequest(DWORD idInst, HCONV hConv, char* szItem, char* sDesc)
{
HSZ hszItem = DdeCreateStringHandle(idInst,LPCTSTR(szItem), 0);
HDDEDATA hData = DdeClientTransaction(NULL,0,hConv,hszItem,CF_TEXT,XTYP_REQUEST,5000 , NULL);
if (hData==NULL)
{
printf("Request failed: %s\n", szItem);
}
else
{
char szResult[255];
DdeGetData(hData, (unsigned char *)szResult, 255, 0);
sDesc = "";
printf("%s%s\n", sDesc, szResult);
}
}
char* cellString(char szItem[])
{
char firstCh = szItem[0];
char strRow[2] = "";
char strCol[3] = "";
int i,j = 0;
int strLength = (int)(strlen(szItem));
for(i=1;i<strLength;)
{
strRow[j] = szItem[i];
i++;
j++;
}
strRow[j] = '\0';
switch(toupper(firstCh))
{
case 'A':strcpy(strCol,"C1");break;
case 'B':strcpy(strCol,"C2");break;
case 'C':strcpy(strCol,"C3");break;
case 'D':strcpy(strCol,"C4");break;
case 'E':strcpy(strCol,"C5");break;
case 'F':strcpy(strCol,"C6");break;
case 'G':strcpy(strCol,"C7");break;
case 'H':strcpy(strCol,"C8");break;
case 'I':strcpy(strCol,"C9");break;
case 'J':strcpy(strCol,"C10");break;
case 'K':strcpy(strCol,"C11");break;
case 'L':strcpy(strCol,"C12");break;
case 'M':strcpy(strCol,"C13");break;
case 'N':strcpy(strCol,"C14");break;
case 'O':strcpy(strCol,"C15");break;
case 'P':strcpy(strCol,"C16");break;
case 'Q':strcpy(strCol,"C17");break;
case 'R':strcpy(strCol,"C18");break;
case 'S':strcpy(strCol,"C19");break;
case 'T':strcpy(strCol,"C20");break;
case 'U':strcpy(strCol,"C21");break;
case 'V':strcpy(strCol,"C22");break;
case 'W':strcpy(strCol,"C23");break;
case 'X':strcpy(strCol,"C24");break;
case 'Y':strcpy(strCol,"C25");break;
case 'Z':strcpy(strCol,"C26");break;
}
szItem = strcpy(szItem,"R");
szItem = strcat(szItem,strRow);
szItem = strcat(szItem,strCol);
return szItem;
}
int DDECall(char szApp[],char szTopic[],char szCmd[],char szInItem[])
{
char szDesc[] = "Requested Cell Value Contains: ";
char* szItem = cellString(szInItem);
//strcpy(szItem,"R13C4");
FILE *fp;
DWORD idInst=0;
UINT iReturn;
iReturn = DdeInitialize((LPDWORD)&idInst, (PFNCALLBACK)DdeCallback,APPCMD_CLIENTONLY, 0L );
/*DdeInitialize() :-
The DdeInitialize function registers an application with the Dynamic Data Exchange Management Library (DDEML).
An application must call this function before calling any other Dynamic Data Exchange Management Library (DDEML)
function.*/
if (iReturn!=DMLERR_NO_ERROR)
{
/*If Error occurs while initialiing DDE then the error code is written to the Log.*/
printf("DDE Initialization Failed: 0x%04x\n", iReturn);
fp = fopen("DdeErrorLog.txt","w+");
fprintf(fp,"\nError Code : DMLERR_DLL_USAGE | DMLERR_INVALIDPARAMETER | DMLERR_SYS_ERROR");
fprintf(fp,"\n\n This Error occurs if Dynamic Data Exchange fails to Initialize ");
fclose(fp);
Sleep(1500);
return 0;
}
HSZ hszApp;
hszApp = DdeCreateStringHandle(DWORD(idInst),LPCTSTR("EXCEL"),CP_WINANSI);
/* DdeCreateStringHandle() :-
The DdeCreateStringHandle function creates a handle that identifies the specified string.
a Dynamic Data Exchange (DDE) client or server application can pass the string handle as
a parameter to other Dynamic Data Exchange Management Library (DDEML) functions.*/
//Start DDE Server and wait for it to become idle.
HINSTANCE hRet = ShellExecute(NULL , "open", "C:\\Test.xls", NULL,NULL, SW_NORMAL);
if ((int)hRet < 33)
{
printf("Unable to Start DDE Server: 0x%04x\n", hRet);
Sleep(1500);
DdeUninitialize(idInst);
return 0;
}
Sleep(1000);
//DDE Connect to Server using given AppName and topic.
HSZ hszTopic;
HCONV hConv;
hszApp = DdeCreateStringHandleA(idInst,LPCTSTR("EXCEL"),CP_WINANSI);
hszTopic = DdeCreateStringHandleA(idInst,LPCTSTR(szTopic), 0);
hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
DdeFreeStringHandle(idInst, hszApp);
DdeFreeStringHandle(idInst, hszTopic);
if (hConv == NULL)
{
printf("DDE Connection Failed.\n");
Sleep(1500);
DdeUninitialize(idInst);
/*The DdeUninitialize function frees all Dynamic Data Exchange Management Library
(DDEML) resources associated with the calling application.*/
return 0;
}
DDEExecute(DWORD(idInst), hConv, szCmd);
/*Sends a command to another application, using dynamic data exchange (DDE).*/
DDERequest(idInst, hConv, szItem, szDesc);
//DDE Disconnect and Uninitialize.
DdeDisconnect(hConv);
DdeUninitialize(idInst);
Sleep(3000000);
return 1;
}
int main()
{
char szApp[] = "EXCEL";
char szTopic[] = "C:\\Test.xls";
char szCmd[] = "[APP.MINIMIZE()]";
char szItem[] = "A1";
DDECall(szApp,szTopic,szCmd,szItem);
getch();
return 0;
}
Thanks & Regards
Vishrant Shah
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Your problem is in this line: char strCol[3] = "";
It can only hold TWO chars, counting the null terminator. So when you do: case 'J':strcpy(strCol,"C10");break;, you're overwriting the null terminator plus whatever follows strCol in memory.
|
|
|
|
|
How to dial a phone number ???
or in other words, i want to make a call from a PC connected to the phone line via some modem, then send some string.
plz help me ...
|
|
|
|
|
|
can RasDial be used without batch files, i mean through the VC++ program itself ???
|
|
|
|
|
tina- wrote: can RasDial be used without batch files,
see here[^] and here[^].
|
|
|
|
|
You are confusing rasdial.exe with RasDial() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
can i use the RasDial command with the system function ?
|
|
|
|
|
tina- wrote: or in other words, i want to make a call from a PC connected to the phone line via some modem, then send some string.
What do you mean by send some strings to the phone ?
|
|
|
|
|
i want to connect to the telephone the same way the dial-up internet connection works.
in my project, the server is to dial the telephone number of the client, at client side, the phone will check the caller's number, if its server's, then i want the server to communicate with the client thro the telephone line.
|
|
|
|
|
OK - that's the entire assignment. We need to know what have you accomplished in the assignment by far and what exactly do you need help with, at the moment.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
So I think its better you see my previous reply.
|
|
|
|
|
|
okay ..... i got it ...
i can now connect to the telephone line through the command prompt.
can use the rasdial command with system() finction ???
|
|
|
|
|
rasdial is working with system()
but the first argument is the phonebook entry, i want some help on that ..
|
|
|
|
|
You can use of it on the vc++ code.
|
|
|
|
|
Hi!
I'm developing a VC++ Application. When I close the application(Window), it shows me the following exceptions in the output area:
First-chance exception at 0x7c81eb33 in CharacterAnimation.exe: Microsoft C++ exception: std::ios_base::failure at memory location 0x0012ef30..
First-chance exception at 0x7c81eb33 in CharacterAnimation.exe: Microsoft C++ exception: std::ios_base::failure at memory location 0x0012f034..
What might be the cause of these exceptions? How do I overcome these exceptions?
|
|
|
|
|
Use your debugger and try to see what might be wrong when the exception is fired: inspect variables, memory, ... It will be much more easier to track the problem once you have more information.
|
|
|
|
|
How do I see the Debugger?
|
|
|
|
|
Err, you don't "see" it, you use it. Press F5 to start the debugger, then you will be able to put breakpoints in your code using F9. See where the crash occurs and look at the call stack to locate the problem in your sources. Then inspect the different variables before the crash occured.
|
|
|
|
|
No crash occurs. After I manually closed the application,
First-chance exception at 0x7c81eb33 in CharacterAnimation.exe: Microsoft C++ exception: std::ios_base::failure at memory location 0x0012ef30..
First-chance exception at 0x7c81eb33 in CharacterAnimation.exe: Microsoft C++ exception: std::ios_base::failure at memory location 0x0012f034..
These two lines are displayed in the Output area.
|
|
|
|
|
Well then just put some breakpoints just before your application exists and go steps-by-steps (check what are the shortcuts because I don't remember by heart).
|
|
|
|
|