Quantcast
Channel: Visual C forum
Viewing all 15302 articles
Browse latest View live

MFC Multibyte code page 1251 not displaying Russian characters

$
0
0

I'm working on a large, complex application that still uses mbcs.  We were asked to add Russian language support.  We made the necessary changes, and on our test machines, set to Russian locale, most of the strings show up as proper Russian.  However, there are several places in the UI where the strings show up as "garbage" text.  We've verified the strings displayed are coming from the resources, so it is not an access issue.

I'm focusing on one issue for now, where we display a property sheet with several tabs and all but two of the tabs show proper Russian.  One observation is that for the tabs that display proper Russian, the resources live in the main .exe.  The two tabs that do not display Russian, their resources live in an MFC extension dll.  (This may be a coincidence, but I mention it anyway.)

The top of the .rc file for the problem tabs specify codepage 1251 (Cyrillic)

LANGUAGE LANG_RUSSIAN, SUBLANG_RUSSIAN_RUSSIA
#pragma code_page(1251)

The dialog itself (DIALOGEX) specifies "MS Shell Dlg" for the font, and the font statement specifies "DEFAULT_CHARSET" (int value 1) like this:

IDD_AZ_ANALYSISPAGE DIALOGEX 0, 0, 421, 366
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Анализ"
FONT 8, "MS Shell Dlg", 0, 0, 1

Here is the resulting dialog.  (Sorry, I am unable to post images or URLs for some reason, so you'll have to copy the url to your browser)

https://dl.dropboxusercontent.com/u/17010956/SettingsDlg.jpg 

I'd like to point out a few things about this dialog.

1.  Some of the property sheet elements show Russian (Cyrillic) characters.  They were loaded explicitly via a LoadString() call and set on the UI in the OnInitDialog() call.

2. Only two of the tabs do not show Russian characters.

3. The dialog resources for the two tabs that do not show Russian live in a MFC extension dll.  The tabs that show Russian have their resources in the main executable.

As a first thought from this, it seems the problem is related to the resources living in a MFC extension dll.  I'm aware of the AFX_MANAGE_STATE macro and this is not the cause of the problem.  The app can *find* and *load* the resources - it is just not displaying them properly.

As part of diagnosing this problem, I added code to the property sheet's "OnInitDialog()" method to get the code page and character set using "GetACP()", "CFont::GetLogFont()" and "GetCPInfoEx()" to get the thread's code page.

Everything was correct.  The charset was RUSSIAN_CHARSET (204) and the code page was 1251 for both the OS and the current thread.

Another developer on the team has found a different property sheet dialog where some of the controls in a single property sheet display Russian and other display the "garbage" text.  He found that if he simply moved some of the lines from the bottom of the dialog resource template to the top, it would affect which controls were affected by this problem.

Any MFC localization experts out there have any idea what might be going on?  Or possibly some diagnostic things we can try?

Thanks,

Terry Henning
Senior Software Engineer


MFC Based Dialog application to add data to Table Created in SQL Server

$
0
0

Hello All;

I want a help regarding creating a MFC based dialog application in Visual Studio 2010 in which i have one button "Add To Database" through which i can add data to the table already created in Microsoft SQL Server Management Studio 2008.

The fields i have kept is Name, Age, Gender and City and i want all this information to display in a table created in SQL Server Management Studio through a MFC based dialog based application.

Help please and give suggestions.

Thanks.

Issues with File paths

$
0
0

I am a brand new user so im probably not doing something right but i am having trouble doing a tutorial thar i found on youtube. I think i follwed the instructions pretty good but i am having some trouble with the paths

Error1 error C1083: Cannot open include file: 'isostream': No such file or directory


2IntelliSense: cannot open source file "isostream"

3IntelliSense: identifier "cout" is undefined

 

4IntelliSense: identifier "endl" is undefined

5IntelliSense: identifier "cin" is undefined


EditBin Dependencies

$
0
0

Hi,

I am planning to use EditBin and DumpBin exe as a part of my Build process in teamCity. I am not planning to to install VS 2010 on the build agent.

Just wanted to check if these exectable can be used without installing VS on build agent. If not, what all do I need to install to make it working.

Thanks.

Error when instantiating ADODB ConnectionPtr on Windows Server 2008

$
0
0

I have an application that I have compiled on Windows 7 64-bit. It works fine on that PC, but I am now trying to get it to work on Windows Server 2008 R2 Standard.

Whenever I try and instantiate ADODB::Connection, I receive the following error:

HRESULT : No such interface supported; hr=0x80004002

Code that generates the error is below:

CoInitialize(NULL);
_ConnectionPtr link;
link.CreateInstance(__uuidof(Connection) );
if (link == NULL) {
    _com_error err(hr);
    Error(err);
}

Now I found this thread: http://social.msdn.microsoft.com/Forums/vstudio/en-US/12c95ba7-60ed-4303-b4da-e811150b8d13/cannot-able-to-instance-adodbconnection-in-2008-r2-server-core-no-such-interface-supported?forum=vcgeneral , but none of the suggestions there have worked.

Any ideas anyone? Thanks in advance


School project, temperature and starting it over again

$
0
0

Hello. I need help on a school project. 

I am trying to make a program where the user can type in the days in month and then type in the lowest (between -70 and 70) and highest (between the lowest and 70) temperature of each day in that month and the amount of rain. At the end it will display the average of these temperatures and the rain and then ask the user if he/she wants to do this again. 

I just need some guidance on how to do this. Any answer is appreciated :) 

this is what I have right now: (i am new to programming so I don't know alot)

int days = 0, tempHigh, tempLow;		
	int tempHighTotal = 0, tempLowTotal = 0;		
	float averageHighTemp, averageLowTemp, averageRain;		
	int rain, rainTotal = 0;		
	int count = 0, countTotal = 0;		
	char choice;		

					
	while (days < 3 || days > 30)
	{
		cout << "Enter the number of days in a month: "; cin >> days;
	}

	for (count = 0; count < days; count++)
	{
		cout << "\nEnter the highest temperature of a day: "; cin >> tempHigh;
		cout << "Enter the lowes temperataure of a day: "; cin >> tempLow;
		cout << "Enter the amount of rain this day (in mm): "; cin >> rain;
		countTotal += count;
		tempHighTotal += tempHigh;
		tempLowTotal += tempLow;
		rainTotal += rain;
	}

	averageHighTemp = tempHighTotal / countTotal;
	averageLowTemp = tempLowTotal / countTotal;
	averageRain = rainTotal / countTotal;
	cout << "\nAverage high temperature: " << averageHighTemp;
	cout << "\nAverage low temperature: " << averageRain;
	cout << "\nAverage rain: " << averageLowTemp;
	cout << "\n\n";
	cout << "Do you want to do this again? "; cin >> choice;


WaitComEvent issue.

$
0
0

Hi,

Recently I was testing my serial comport reading code by sending a file through comport using teraterm and logging it from another comport through loop back cable.

What I observed was I have opened comport synchronously and waiting on WaitComEvent for EV_RXCHAR event and then reading bytes present in device buffer by ClearCommError and then writing the buffer onto a file.

But what i observed was cbInQue member of the structure returned by ClearCommError was 0.

How is this possible that EV_RXCHAR event was generated when there were no bytes in the device buffer.

If it is possible that the next coming buffer had set the EV_RXCHAR internally then how can I overcome this.

Here is the pseudocode for your refrence

//Opening comport

m_ComHandle = CreateFile(pDlg->m_ComNumStr,GENERIC_READ|GENERIC_WRITE,
        0,
        0,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,0);

//setting timeouts

CommTimeOuts.ReadIntervalTimeout = MAXDWORD;   

        
        CommTimeOuts.ReadTotalTimeoutMultiplier = 0;    //This multipied with no of bytes gives the value
        CommTimeOuts.ReadTotalTimeoutConstant = 0;    //This is added to previously computed values
        CommTimeOuts.WriteTotalTimeoutMultiplier = 0 ;
        CommTimeOuts.WriteTotalTimeoutConstant = 1000;

        if(!SetCommTimeouts (pDlg->m_ComHandle, &CommTimeOuts))
        {
             pDlg->ExitFunction();
             AfxMessageBox(_T("Unable to set time outs"));
            
             return 1;

        }

while(1){
   if (WaitCommEvent(pDlg->m_ComHandle, &dwCommEvent, NULL))
   {
       if(dwCommEvent & EV_RXCHAR)
       {
            ClearCommError(pDlg->m_ComHandle,&error_got,&comm_info);
            bytes_in_que = comm_info.cbInQue;
            sprintf(buffer + index,"%d\n",bytes_in_que);
            index = strlen(buffer);
            if(index >= 1000)
            {
                 index = 0;
                 fwrite(buffer,strlen(buffer),sizeof(T_CHAR),pDlg->fp_bytesinq);
                 memset(buffer,0,sizeof(buffer));
            }
            ptr = (T_UCHAR*)malloc(sizeof(T_UCHAR)*bytes_in_que);
            if(ReadFile(pDlg->m_ComHandle,ptr,bytes_in_que,&bytes_read,NULL))
            {
                 if(bytes_read != bytes_in_que)
                 {
                     AfxMessageBox(_T("Some error occured while reading(Less bytes read)"));
                     break;
                 }
                 else
                 {
                    
                     fwrite(ptr,bytes_read,sizeof(BYTE),pDlg->fp_log);
                     fprintf(pDlg->fp_log,",%ubytes\n",bytes_read);
                     free(ptr);
                 }
            }
            else
            {
                 AfxMessageBox(_T("Some error occured while reading"));
                     break;
            }
        }
   }
   else
   {
      AfxMessageBox(_T("Some error occured when waiting for EV_RXCHAR event"));
      break;
    }
    }

Regards,

Amrut


Amrut.s.a

error C2664: 'int swscanf_s(const wchar_t *,const wchar_t *,...)' : cannot convert argument 1 from 'const TCHAR *' to 'const wchar_t *'

$
0
0

Hi,

Am once again trying to compile a direct x sample from Frank Luna but these are 2 errors that are stopping the executable being produced.

1>dxutil.cpp(868): error C2664: 'int swscanf_s(const wchar_t *,const wchar_t *,...)' : cannot convert argument 1 from 'const TCHAR *' to 'const wchar_t *'

1>dxutil.cpp(905): error C2664: 'int _snwprintf(wchar_t *,size_t,const wchar_t *,...)' : cannot convert argument 1 from 'TCHAR *' to 'wchar_t *'

Any ideas how to resolve these issues? I`m guessing maybe a type cast of some sort but i`m a newbie so i really don`t know for sure.


Need code for "if checkbox checked then download file"

$
0
0

Hi everyone,

I'm newbie in programing and I want create a C++ software with Visual Studio 2013 that contains checkboxes and two buttons like download and cancel and one progressbar. So, I need code for this. Appreciated for an simple code if possible.

Thanks.


Cannot convert argument 1 from 'unsigned char **' to const unsigned char **'

$
0
0

Hi, When compiling the below piece of code I'm getting an unexpected error for my testB method: C2664: Cannot convert argument 1 from 'unsigned char **' to const unsigned char **' 

However my calls to testA compile without issue.

Why is the compiler able to understand that:

unsigned char * converts to const unsigned char *

Yet:

unsigned char ** Does NOT convert to const unsigned char **

Here's the code:

#include "stdafx.h"

int testA(const unsigned char *bptr) // Const unsigned char * (works with no error)
{
	return 1;
}

int testB(const unsigned char **cptr)    // Const unsigned char ** (causes compiler error)
{
	return 1;
}

int _tmain(int argc, _TCHAR* argv[])
{
	unsigned char * ab;
	unsigned char * bb;
	
	testA(bb); // Compiles as expected

	testB(&ab); // error C2664 cannot convert argument 1 from 'unsigned char **' to 'const unsigned char **'
	return 0;
}

self learner

$
0
0
Using this information "Walkthrough:Creating and Using a Static Library (C++)" I created and compiled a static library, added a Class to utilize the library. After creating a program to refer to this library, during the build I was to referrence the library. In attempting to do this I was unable to find the library I created to be referrenced. Can anyone advise me in what I may be missing?

WaitComEvent issue.

$
0
0

Hi,

Recently I was testing my serial comport reading code by sending a file through comport using teraterm and logging it from another comport through loop back cable.

What I observed was I have opened comport synchronously and waiting on WaitComEvent for EV_RXCHAR event and then reading bytes present in device buffer by ClearCommError and then writing the buffer onto a file.

But what i observed was cbInQue member of the structure returned by ClearCommError was 0.

How is this possible that EV_RXCHAR event was generated when there were no bytes in the device buffer.

If it is possible that the next coming buffer had set the EV_RXCHAR internally then how can I overcome this.

Here is the pseudocode for your refrence

//Opening comport

m_ComHandle = CreateFile(pDlg->m_ComNumStr,GENERIC_READ|GENERIC_WRITE,
        0,
        0,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,0);

//setting timeouts

CommTimeOuts.ReadIntervalTimeout = MAXDWORD;   

        
        CommTimeOuts.ReadTotalTimeoutMultiplier = 0;    //This multipied with no of bytes gives the value
        CommTimeOuts.ReadTotalTimeoutConstant = 0;    //This is added to previously computed values
        CommTimeOuts.WriteTotalTimeoutMultiplier = 0 ;
        CommTimeOuts.WriteTotalTimeoutConstant = 1000;

        if(!SetCommTimeouts (pDlg->m_ComHandle, &CommTimeOuts))
        {
             pDlg->ExitFunction();
             AfxMessageBox(_T("Unable to set time outs"));
             return 1;

        }

while(1){
   if (WaitCommEvent(pDlg->m_ComHandle, &dwCommEvent, NULL))
   {
       if(dwCommEvent & EV_RXCHAR)
       {
            ClearCommError(pDlg->m_ComHandle,&error_got,&comm_info);
            bytes_in_que = comm_info.cbInQue;                      //Here Bytes in queue is 0
            sprintf(buffer + index,"%d\n",bytes_in_que);
            index = strlen(buffer);
            if(index >= 1000)
            {
                 index = 0;
                 fwrite(buffer,strlen(buffer),sizeof(T_CHAR),pDlg->fp_bytesinq);
                 memset(buffer,0,sizeof(buffer));
            }
            ptr = (T_UCHAR*)malloc(sizeof(T_UCHAR)*bytes_in_que);
            if(ReadFile(pDlg->m_ComHandle,ptr,bytes_in_que,&bytes_read,NULL))
            {
                 if(bytes_read != bytes_in_que)
                 {
                     AfxMessageBox(_T("Some error occured while reading(Less bytes read)"));
                     break;
                 }
                 else
                 {
                     fwrite(ptr,bytes_read,sizeof(BYTE),pDlg->fp_log);
                     fprintf(pDlg->fp_log,",%ubytes\n",bytes_read);
                     free(ptr);
                 }
            }
            else
            {
                 AfxMessageBox(_T("Some error occured while reading"));
                     break;
            }
        }
   }
   else
   {
      AfxMessageBox(_T("Some error occured when waiting for EV_RXCHAR event"));
      break;
    }
    }


Regards,

Amrut


Amrut.s.a

Upgrading a big project from VC++ 6.0 to the newest version possible ( VC++ 2010 or VC++2012)

$
0
0
Hello all,

I am working on a old software source coded in VC++ 6.0. It's the first time I use this language and we are thinking with our client about upgrading the program to a newer version of VC++ so it can compile in recent machines.

-First, What do you think about upgrading a big project to a newer version ? Will it take a long time or is it easy ?
(Because I saw a lot of forums where they simply say " use the ms vs converter " or " create new project from existing file ")

-I also saw a lot of threads that say the best way is first to upgrade the project to VC++ 2008 then to a newer version if needed ? Then do you know any good tutorial explaining step by step the way to upgrade such a project ?
(Because I saw different way to do this but I did not understand very well how to do it :
for exemple : http://otb.manusoft.com/2010/10/visual-studio-2010-native-multi-targeting.htm )

-Finally, can you please tell me wich issues I may face during an upgrade ? So I can try to learn about how to change the program or settings for avoiding these problems ?

Thanks a lot, and sorry for my english mistakes I am not a native speeker.

Omar

how to make file explorer recognize private clipboard format?

$
0
0
use RegisterClipboardFormat(TYPE_XXX) to register clipboard format, use setclipboarddata() to fill clipboard, how to make file explorer to recognize the format? Registry or other methods? Any advice is appreciated. Thanks!

Application by using more than 65535 UDP ports

$
0
0

Hello all!

I'm now implementing a device simulator in VC++ to performance a load test to our server application. I need to simulate a huge number of devices to communicate with this server via UDP, each device shall have its own UDP port exclusive during the simulation.

Since there are maximal 65536 ports pro IP address and from 0 to 1024 are reserved by OS, theoretically I have 64511 free ports for my Simulator application, considering some ports are required by some services/applications, the free port number may a little fewer, I'm assuming this number is 60000. According to our software requirement, I can't reach the required simulating device amount under this port limitation.

If I'm right, if one computer has more IPs, I shall have more than 60000 free ports. My simulator runs under Windows Server 2008, 2 physical network adapters and I used following command to change the dynamic UDP port range to get 60000 UDP ports:
      netsh interface ipv4 set dynamicportrange protocol=udp startport=3000 numberofports=60000
      
My questions are:

1. Is this setting globally available or for each IP address?
   I tried to set the parameter "numberofports" to 120000 but it didn't work.
  
2. Shall I set for each IP address separately a UDP port range?
  
3. If this setting is for each IP addres available, I have following problem:
   For two IP address, I could bind 60000 ports in total to 60000 UDP sockets, e.g IP1 20000 ports and IP2 40000 ports, or IP1 40000 ports and IP2 20000 ports. That means I can still use maximal 60000 UDP ports.
  
  
Unfortunately, I can't find any reference about this topic in Internet, does anyone have my similar situation?

Thank you in advance to teach me a solution!


Com Port Configuration.

$
0
0

Hi,

I wanted to know can I programmatically identify the baud rate,stop bits,parity of the data coming at a comport.

If it is possible can you help with some useful links

Regards,

Amrut


Amrut.s.a

build not performing link command

$
0
0

We are having a problem with Visual Studio 2013.  Basically, after an initial build and a subsequent edit to source code, build (either from the Build menu, or F7, or when we press F5 or Ctrl-F5 and click yes on the build prompt) compiles the source file, claims it successfully builds, but never runs the link.exe command.  (This is reflected in the build log file - it shows the link step, but there is no command line showing link.exe and the options to it, as is shown when you do a full rebuild.  You can also see from the file timestamps that the .obj file is being recreated, but not the .exe.) 

I thought it was a dependencies issue, but I can delete the .exe file entirely and it still won't recognize that it needs to link.  I've tried a bunch of different settings in the Project Properties with no success.  I'm out of debugging ideas - anyone else seen this, know what it is, or how to fix it?  For now, I just have to clean before building every time.



WSASend and WSAEWOULDBLOCK

$
0
0

Windows 7 and XP, Visual Studio 2008, 2012, C++

Non blocking sockets, overlapped I/O, completion events

I do not have the code working yet but am writing the mechanisms to handle error conditions. 

Question: What should be done if WSASend() solicits the error WSAEWOULDBLOCK

Presume the link has been established and some number of sends have successfully completed.

This page:http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx#WSAEWOULDBLOCK

Says, in part: It is a nonfatal error, and the operation should be retried later.

I am hoping someone will provide a better definition of: later

Should the code call Sleep( x ). Is there an event or some other indicator that can trigger actions “later?”

I have searched this for a while and did not find an answer. If you have a link to an answer, that would be cool. 


~jag77 We need to know what a dragon is before we study its anatomy. (Bryan Kelly, 2010)

Pass data from 'C' program to 'C++' program to 'C#' program using VS 2013

$
0
0

Hello,

I’m using Visual Studio 2013 Pro where I have a solution with three projects; A ‘C’ Project, a ‘C++’ project and a ‘C#’ project.

This builds OK and when I call the ‘C’ program from another environment it executes well and the final result of the ‘C#’ program is executed. That’s not a problem when there is no data passing back and forth.

I’m trying to get the linkage and data passing down so that the program that calls the ‘C’ program can pass it some data, the ‘C’ program then calls the ‘C++’ program and passes it the data and finally the ‘C++’ program calls the ‘C#’ program and passes it the data.

Then I need the ‘C#’ program to pass back a dataset to the ‘C++’ program and the ‘C++’ program passes it back to the ‘C’ program.

I have read numerous articles on external linking and program intercommunication, but I am not able to get the data from the ‘C’ program to the ‘C++’ program. When I put a MessageBox.Show in the ‘C++’ program to display the external data, it only displays one character; a capital C, which is the first character of the data I am trying to pass.

I have put the three small, simple programs at the end of this post.

Does anybody have any information or coding pointers to help me solve this problem?

Any help would be gratefully appreciated.

Thanks,
Tony

#include "stdafx.h"

extern __declspec(dllimport) int MainCPP(char retFromCPP); extern __declspec(dllexport) int ProjectCTest(char *retToCobol); int ProjectCTest(char *txtFromCobol) { char returnAnswer; returnAnswer = MainCPP(*txtFromCobol); return 0; }

// CPPCLibrary.h
#pragma once

using namespace System;
using namespace System::Windows::Forms;

	extern "C" __declspec(dllexport) int MainCPP(char txtFromPCT)
	{
		MessageBox::Show("Ready to call frmMain: " + txtFromPCT);
		return LakesideConsumeServices::Program::Main(txtFromPCT);
	}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LakesideConsumeServices
{
    static public class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static public int Main(char args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
            return 0;
        }
    }
}



Stop The World, I want To Get Off! ........... Life Isn't About Waiting For The Storm To Pass ... It's About Learning To Dance In The Rain.

Visual Studio won't let you create an variable sized array in C

$
0
0

In linux gcc, you can create an array and use a variable as size. When you try to do the same in Visual Studio, IntelliSense says that expression must have a constant value. I've researched about it, but it's still not clear to me why this happens in Visual Studio. Is there any chance for this to change in a future update?

void main(){

int a;

int v[a];

}

Note that it's C, not C++ (I posted on C++ forums because apparently there isn't a C one).



Viewing all 15302 articles
Browse latest View live