Click here to Skip to main content
15,915,164 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: How to get ASCII Character from Decimal value Pin
James R. Twine18-Jun-08 3:35
James R. Twine18-Jun-08 3:35 
QuestionProperty Sheet eVC++ WinCE - Urgent Pin
Trupti Mehta18-Jun-08 2:54
Trupti Mehta18-Jun-08 2:54 
Questionget internal ip, getaddrinfo() Pin
smedowns7718-Jun-08 2:50
smedowns7718-Jun-08 2:50 
QuestionRe: get internal ip, getaddrinfo() Pin
David Crow18-Jun-08 2:57
David Crow18-Jun-08 2:57 
AnswerRe: get internal ip, getaddrinfo() Pin
Jijo.Raj18-Jun-08 3:01
Jijo.Raj18-Jun-08 3:01 
AnswerRe: get internal ip, getaddrinfo() Pin
Mark Salsbery18-Jun-08 10:23
Mark Salsbery18-Jun-08 10:23 
QuestionKeyboard messages not received by my window Pin
theCPkid18-Jun-08 2:24
theCPkid18-Jun-08 2:24 
QuestionDynamic Data Exchange using C++ : Urgent Pin
Vishrant Shah18-Jun-08 0:38
Vishrant Shah18-Jun-08 0:38 
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
GeneralUrgent? No cookie for you... Pin
CPallini18-Jun-08 1:41
mveCPallini18-Jun-08 1:41 
AnswerRe: Dynamic Data Exchange using C++ : Urgent Pin
Alan Balkany18-Jun-08 3:36
Alan Balkany18-Jun-08 3:36 
QuestionHow to dial a phone number ??? Pin
tina->newcoder18-Jun-08 0:32
tina->newcoder18-Jun-08 0:32 
AnswerRe: How to dial a phone number ??? Pin
Hamid_RT18-Jun-08 0:40
Hamid_RT18-Jun-08 0:40 
GeneralRe: How to dial a phone number ??? Pin
tina->newcoder18-Jun-08 0:49
tina->newcoder18-Jun-08 0:49 
GeneralRe: How to dial a phone number ??? Pin
Hamid_RT18-Jun-08 1:02
Hamid_RT18-Jun-08 1:02 
GeneralRe: How to dial a phone number ??? Pin
David Crow18-Jun-08 3:21
David Crow18-Jun-08 3:21 
GeneralRe: How to dial a phone number ??? Pin
tina->newcoder18-Jun-08 1:02
tina->newcoder18-Jun-08 1:02 
AnswerRe: How to dial a phone number ??? Pin
Cedric Moonen18-Jun-08 0:59
Cedric Moonen18-Jun-08 0:59 
GeneralRe: How to dial a phone number ??? Pin
tina->newcoder18-Jun-08 1:08
tina->newcoder18-Jun-08 1:08 
GeneralRe: How to dial a phone number ??? Pin
Rajesh R Subramanian18-Jun-08 1:15
professionalRajesh R Subramanian18-Jun-08 1:15 
GeneralRe: How to dial a phone number ??? Pin
Hamid_RT18-Jun-08 1:28
Hamid_RT18-Jun-08 1:28 
JokeRe: How to dial a phone number ??? Pin
Maximilien18-Jun-08 1:32
Maximilien18-Jun-08 1:32 
AnswerRe: How to dial a phone number ??? Pin
tina->newcoder18-Jun-08 1:31
tina->newcoder18-Jun-08 1:31 
GeneralRe: How to dial a phone number ??? Pin
tina->newcoder18-Jun-08 1:39
tina->newcoder18-Jun-08 1:39 
GeneralRe: How to dial a phone number ??? Pin
Hamid_RT18-Jun-08 6:32
Hamid_RT18-Jun-08 6:32 
Questionstd::ios::base Exception Pin
T.RATHA KRISHNAN18-Jun-08 0:19
T.RATHA KRISHNAN18-Jun-08 0:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.