From: mohan on 19 May 2010 03:24 Hi, I have developed a VB.NET2008 application (32 bit ) for GUI automation. It is calling some methodes from VC6 dlls , /win32 APIs and hook APIs(code injection). Inorder to support the 64bit/win7 applications, I have tried to compile all my dlls and VB.NEt application in 64 bit mode. I am facing the following issues: 1) Ported my VC6 code to VS2008 32 bit and removed all the warnings (almost 150warnings- all are security related).Now compiled again the code with x64 and I am getting lot of warnings as given below. Example : code :- int nLen =strlen(strToappend); Warnings:'initializing ' conversion from 'size_t' to 'int', possible loss of data 2) Without removing the warning messages , I have used the x64 dll (VC6 dll) to the VB.Net applications and I am getting the "Debug assertion failed" as given below: File:f:\dd\vctools\crt_bld\self_64_amd64\crt\src\strtok_s.inl line 20 Expression (_Context)!=NULL Example code (calling VC6 dlls from VB.NET) Decalartion: Public Declare Function TekRoboEditBoxClick Lib "TekRobo.dll" (ByVal WindowName As String, ByVal label As String, ByVal edititem As String) As Integer Methode from VC6 code: int _stdcall TekRoboEditBoxClick(char szWindowTilte[],char szLabel[],char szEditItem[]) { HWND hWnd1,hWnd2,hWnd3; RECT rc; int nRet =TEKROBO_ERR; char *strret=NULL; char szClass[256]; char *szLabelID = new char[256]; bSuccess = FALSE; bFindControl = FALSE; bFindHandle=FALSE; hwndstatic=NULL; int value =0; short VKeycode,nHighByte,nLowByte; char *szControlName = new char [256]; strcpy_s(szControlName,256,szLabel); try { if(szLabel!=NULL) { strret=strstr(szLabel, "ID"); if(strret!=NULL) { strcpy_s(szLabelID,256,szLabel); bControlID=TRUE; //parse the controlID from string ParseStringforbuttoncontrols(szLabelID,szLabel); } } // get main window handle hWnd1= ::FindWindow(NULL,szWindowTilte); if(hWnd1!=NULL) { bClickControl = TRUE; hWnd2=::GetWindow(hWnd1,GW_CHILD); hWnd3 =hWnd2; //Added line for mixed if(hWnd2!=NULL) { CheckIDandIndex(szLabel,szControlName); //checking for objectindex int nVal =atoi(szLabel); bool bNotstring =FALSE; if(bControlID==TRUE) { bControlID=FALSE; //if controlID ,get handle through ID ScanControlID(hWnd2,nVal); hWnd2=hwndstatic; } else { for(int j=0; j<= (int)strlen(szControlName); j++) { if((szControlName[j]>='A'&&szControlName[j]<='Z')|| (szControlName[j]>= 'a'&&szControlName[j]<='z')) { bNotstring=TRUE; break; } } //if objectindex ,get handle through index else through label FindClassName(szWindowTilte); if (bDotNet) { sprintf_s(szClass, "%s.%s.%s",g_szPrefix,szWindow, g_szSuffix); } else { strcpy_s(szClass,256,szStatic); } bool bval=FindMFCClass(szWindowTilte); if(bval) { strcpy_s(szClass,256,szStatic); } if(bNotstring==FALSE) ScanIndex(hWnd2,nVal,szClass); else ScanWindowHandle(hWnd2,szClass,szControlName); //if not NULL,get next windows handle if(hwndstatic!=NULL) { hWnd2=hwndstatic; //if it is MFC class,go for next window if(bval) hWnd2=::GetWindow(hWnd2,GW_HWNDNEXT); } else { sprintf_s(szClass,256, "%s.%s.%s",g_szPrefix,szStatic, g_szSuffix); ScanWindowHandle(hWnd2,szClass,szControlName); hWnd2=hwndstatic; if(hWnd2!=NULL) { //if Z order is next window if(bDotNet) hWnd2=::GetWindow(hWnd2,GW_HWNDNEXT); //if Z order is previous window //hWnd2=::GetWindow(hWnd2,GW_HWNDPREV); } else { //added twolines for mixed laungage support on may 1st 2007 ScanControlWithoutClass(hWnd3,szControlName, "STATIC"); hWnd2=hwndstatic; // AfxMessageBox("Inside="); hWnd2=::GetWindow(hWnd2,GW_HWNDNEXT); //return TEKROBO_ERR_WINDOW_NOT_FOUND;//commented for mixed } } } if(hWnd2!=NULL) { // AfxMessageBox("Outsideiswindow="); value=::IsWindowVisible(hWnd2); if(value!=0) { // AfxMessageBox("Insideiswindow="); ::GetWindowRect(hWnd2,&rc); int x =(rc.left+rc.right)/2; int y =(rc.bottom+rc.top)/2; //x=rc.right-5; //set foreground window ::SetForegroundWindow(hWnd1); // set mouse pointer and click on that button nRet = MouseClick(szWindowTilte,x,y); int len =strlen(szEditItem); keybd_event(VK_HOME, 0, 0, 0 ); keybd_event(VK_HOME, 0, KEYEVENTF_KEYUP, 0); keybd_event(VK_SHIFT, 0, 0, 0 ); keybd_event(VK_END, 0, 0, 0 ); keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); keybd_event(VK_END, 0, KEYEVENTF_KEYUP, 0); //::SendMessage(hWnd2,EM_SETSEL,0,-1); Sleep(2000); for (int i=0; i<len; i++) { VKeycode=VkKeyScan(szEditItem[i]); nHighByte=(VKeycode & 0xff00)>>8; BOOL bShiftPressed = (nHighByte & 0x01); nLowByte=(VKeycode&0x00ff); //keybd_event((UCHAR)VkKeyScan(szEditItem[i]), 0, 0, 0 ); if (bShiftPressed) { keybd_event(VK_SHIFT, 0, 0, 0 ); keybd_event((UCHAR)nLowByte, 0, 0, 0 ); keybd_event((UCHAR)nLowByte, 0, KEYEVENTF_KEYUP, 0); keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); } else { keybd_event((UCHAR)nLowByte, 0, 0, 0 ); keybd_event((UCHAR)nLowByte, 0, KEYEVENTF_KEYUP, 0); } } Sleep(2000); keybd_event(VK_RETURN , 0, 0, 0); keybd_event(VK_RETURN , 0, KEYEVENTF_KEYUP, 0); } else { nRet=TEKROBO_ERR_CTRL_NOT_FOUND; } } else { nRet=TEKROBO_ERR_CTRL_NOT_FOUND; } } else { nRet=TEKROBO_ERR_WINDOW_NOT_FOUND; } } else { nRet=TEKROBO_ERR_WINDOW_NOT_FOUND; } } catch (CException*) { return TEKROBO_ERR; } delete [] szLabelID; delete [] szControlName; return nRet; } It would be great if somebody analyze my code and help me to resolve the assertion. Thanks , Mohan
From: David Schwartz on 19 May 2010 22:48 On May 19, 12:24 am, mo...(a)tek.com wrote: > 1) Ported my VC6 code to VS2008 32 bit and removed all the warnings > (almost 150warnings- all are security related).Now compiled again the > code with x64 and I am getting lot of warnings as given below. > Example : > code :- int nLen =strlen(strToappend); > Warnings:'initializing ' conversion from 'size_t' to 'int', possible > loss of data The warning is correct. What if the length of the string pointed to by 'strToappend' doesn't fit in an integer? Why isn't nLen a size_t if it's expected to hold the length of any string? The 'strlen' function is defined to return a 'size_t'. If you want to cast it to an 'int' and you know it's safe, you must say so in your code. [snip] In your other code, I don't see how it calls strtok_r. What's the stack look like when you get the assertion? DS
From: SaticCaster on 20 May 2010 03:41 1) Try Viva64 - http://www.viva64.com 2) Lessons on development of 64-bit C/C++ applications - http://www.viva64.com/articles/x64-lessons/
|
Pages: 1 Prev: ANN: Seed7 Release 2010-05-16 Next: UDP Multicast issue XP SP2 |