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

scanf vs scanf_s

$
0
0

I have an error from scanf.

    error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.

 int a = 0, b = 0;
    char op = 0;
    int result = 0;

    scanf("%d %c %d", &a, &op, &b);

Error disappeared after change it to scanf_s.

What is the difference between scanf and scanf_s?


How to read items from a text file and place them into an array and then compare?

$
0
0
I have two files
  • "line.txt" which contains : abcfurfghthehgiowl
  • "searchwords.txt" : owl tree dog cat the (6 in total)

As you can see not all the words will be in both

I want to place the contents of these files into arrays where I will compare the words. I also want to output wether the word has been found, the index location in the array

for example: "owl", found, location 1

                    "dog", Not found

void SingleParameter(char letters);
void ReadFile(ifstream& infile);

int main()
{
	ifstream infile("line.txt");
	ReadFile(infile);

	ifstream searchTest("searchwords.txt.txt");
	ReadFile(searchTest);

	system("pause");
}

void Char(char letters)
{
	cout << letters;// << endl;
}

void ReadFile(ifstream& infile)
{
	if (!infile)
	{
		cout << "ERROR:";
		cout << "Can't open input file\n";
	}
	else
	{
		infile >> noskipws;
		while (!infile.eof())
		{
			char ch;
			infile >> ch;
			Char(ch);
		}
	}
}


StudiousStudent


How to read items from a text file and place them into an array for comparison?

$
0
0
I have two files
  • "line.txt" which contains : abcfurfghthehgiowl
  • "searchwords.txt" : owl tree dog cat the (6 in total)

As you can see not all the words will be in both

I want to place the contents of these files into arrays where I will compare the words. I also want to output wether the word has been found, the index location in the array

for example: "owl", found, location 1

                    "dog", Not found

I'm not too sure on how to place the info into an array or compare the items either

void SingleParameter(char letters);
void ReadFile(ifstream& infile);

int main()
{
	ifstream infile("line.txt");
	ReadFile(infile);

	ifstream searchTest("searchwords.txt.txt");
	ReadFile(searchTest);

	system("pause");
}

void Char(char letters)
{
	cout << letters;// << endl;
}

void ReadFile(ifstream& infile)
{
	if (!infile)
	{
		cout << "ERROR:";
		cout << "Can't open input file\n";
	}
	else
	{
		infile >> noskipws;
		while (!infile.eof())
		{
			char ch;
			infile >> ch;
			Char(ch);
		}
	}
}


StudiousStudent





How to place contents of a txt file into an array?

$
0
0

I'm new to c++ and have two files

"line.txt" which contains : abcfurfghthehgiowl
"searchwords.txt" : owl tree dog cat the (6 in total)

As you can see not all the words will be in both

I want to place the contents of these files into arrays where I will compare the words. I also want to output wether the word has been found, the index location in the array

for example: "owl", found, location 1

"dog", Not found

I'm not too sure on how to place the info into an array or compare the items either. At the moment I'm able to display the contents of my files but that's all.

voidSingleParameter(char letters);voidReadFile(ifstream& infile);int main(){
	ifstream infile("line.txt");ReadFile(infile);

	ifstream searchTest("searchwords.txt.txt");ReadFile(searchTest);

	system("pause");}voidChar(char letters){
	cout << letters;// << endl;}voidReadFile(ifstream& infile){if(!infile){
		cout <<"ERROR:";
		cout <<"Can't open input file\n";}else{
		infile >> noskipws;while(!infile.eof()){char ch;
			infile >> ch;Char(ch);}}}




StudiousStudent


ribbon control in mfc dialog based application

$
0
0
I am using visual studio 2010 professional edition. I am working on MFC dialog based application

I have created the ribbon resource and try to load the same using the following:-

    m_wndRibbonBar.Create(this);
m_wndRibbonBar.LoadFromResource(IDR_RIBBON);

where CMFCRibbonBar m_wndRibbonBar is declare in the header file as well.

But I can't create the same in dialog based application, it will work in SDI or MDI application.

I would like to create the ribbon control in a dialog based application.

Is there any possibility to do so, if not ; what are the alternatives for the same.

Thanks,


SendMessage, Total Commander and SVN

$
0
0
Hi! I'd like to use SendMessage function to execute some TortoiseSVN functions from Total Commander context menu. Is it even possible? And if so, then how should I choose the params?

ribbon control in mfc dialog based application

$
0
0
I am using visual studio 2010 professional edition. I am working on MFC dialog based application

I have created the ribbon resource and try to load the same using the following:-

    m_wndRibbonBar.Create(this);
m_wndRibbonBar.LoadFromResource(IDR_RIBBON);

where CMFCRibbonBar m_wndRibbonBar is declare in the header file as well.

But I can't create the same in dialog based application, it will work in SDI or MDI application.

I would like to create the ribbon control in a dialog based application.

Is there any possibility to do so, if not ; what are the alternatives for the same.

Thanks,


VS 2017 and VCToolsInstallDir

$
0
0

Hello,

I'm currently testing VS 2017 with our current Solutions which compiles with VS 2015 very well.

I installed parts of VS 2017 professional (WIN 8.1 SDk, no WIN 10 SDK, no VS 2015 Support).

When I open a 2015 solution I was asked to update the Projects to 8.1 SDK and Toolset v141 which I accepted.

But when I Try to build a C++ Project  I get
Warning MSB8003 :

Could not find VCToolsInstallDir variable from the registry

TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.

I searched in the registry and indded VCToolsInstallDir  can not be found.

Which part of VS 2017 is missing ?

 TIA

   Hendrik Schmieder


Simple function pointer example

$
0
0

I made a simple example for function pointer like fowlloing.

#include <stdio.h>
void printname(char* first_name, char* last_name)
{
    printf("full name is %s, %s\n", first_name, last_name);
}

int main()
{
    void (*printname)(char*, char*) = &printname; // Error occur here!
    (*printname) ((char*)"James", (char*)"Bond");

    return 0;
}

However an compile error occur from the line displayed in bold. 

error C2440: 'initializing': cannot convert from 'void (__cdecl **)(char *,char *)' to 'void (__cdecl *)(char *,char *)'
Can anybody fix this?

    

CFileDialog Visual Group Text Color

$
0
0

I'm grouping some ComboBox in my CFileDialog using VisualGroup, how do I change the text label's color in to black?

Wrap SHBrowseForFolder into a DLL

$
0
0

Hi All

This is a bit of a long shot

I use a 3rd party language that can make external function call and could call SHBrowseForFolder however it cannot handle the callback function

I was wondering if anyone had a similar problem and had built a dll in c++ to wrap SHBrowseForFolder in a dll and provides an interface to a third party language so that it could use it successfully

Thanks in advance

Catastrophic error in CFileDialog

$
0
0

In dlgfile.cpp, CFileDialog::ApplyOFNToShellDialog() is called every time my program calls CFileDialog::DoModal().

The first time I call CFileDialog::DoModal(), CFileDialog::ApplyOFNToShellDialog() properly calls IFileDialog::SetFileTypes().

The second time I call CFileDialog::DoModal(), CFileDialog::ApplyOFNToShellDialog() calls IFileDialog::SetFileTypes() again, gets E_UNEXPECTED, and crashes my program.

I'm not going to check if newer versions of Visual Studio fixed this.  10 was the new 6.  A workaround is to set bVistaStyle to FALSE when calling the constructor.

How to turn off "/MP" option in Visual C++ 2008 Express

$
0
0

Hi!

Can't find how to turn off "/MP" option in Visual C++ 2008 Express Edition. Any ideas?

Thank you,

How to get instance of class from Class in External file?

$
0
0

Hello, suppose I have the following 3 files, I want to declare a variable instance of MyContextReactor class in call.cpp

MyClass.cpp

#include "function.h"

class MyContextReactor : public AcEdInputContextReactor { public: void beginGetPoint( const AcGePoint3d* pointIn, const char* promptString, int initGetFlags, const char* pKeywords);

....

private:

....

}

//my function

MyContextReactor::beginGetPoint...

...

Call.cpp

#include "function.h"

MyContextReactor cls;

my questions is:

in function.h file

do I have to declare all the function and variables of function.h again? (If so, I have to copy it twice?)

function.h

#ifdef...

...

#endif

class MyContextReactor : public AcEdInputContextReactor { public: void beginGetPoint( const AcGePoint3d* pointIn, const char* promptString, int initGetFlags, const char* pKeywords);

...

};

Is there any shorter method? please help me.
thanks a lot!


DirectXMath cached memory?

$
0
0

(I hope this isn't off-topic, feel free to redirect me if it is.)

Some DirectXMath functions like XMLoadFloat say that the parameter must reside in cached memory. What is cached memory and how do I get it?


custom DLL not found on windows server 2016 but works in visual studio 2017

$
0
0
I have developed a custom Visual c++ dll , it works properly on visual studio 2017 but does not work on windows sever 2016. It fails with the message DLL not found. I  wrote a simple dll ( adding two integers ) it works fine on server. 

MFC setting question?

$
0
0

hello, i'm creating a normal c ++ project, then if i want to add mfc class so in project settings i choose class wizard but all are disabled
Can I manually fix this in the project settings? I tried changing some settings but failed
I found that some of the MFC projects I downloaded didn't have this problem. (I installed MFC v142)
I didn't know how to solve it.

I am using vsto 2019, Following are some photos showing it:

Do I have to recreate the whole project?
Thanks a lot!


Regarding the GUI

$
0
0

I have just started to work on Microsoft visual c++ express 2010 

And my requirement is I need to build a GUI for particular application

So can anybody suggest me from where to start and how to get all library or codes for different functions so that I can easliy add from the particular library.

and after building my GUI I have to interface or run that GUI with 1553 data bus 

So also need to write code for 1553 data transfer through my GUI.

so please help me from where i can start building my GUI 

Here I am attaching word file having requirement and outlook for my GUI

note::

So this is basic outlook of my GUI and apart from warning signal remaining inputs have only simple button along with their names and info but in the warning signal when I press warning signal tab I should able to see 20 different tabs with names as warning signal_0-------warning signal_50
So I should have 50 tabs inside warning signal so how to do that. ??



Device context size is getting reduced during redrawing

$
0
0

Hi,

We have an application window which is developed under VC++ to display some information’s like text and some numbers.
This window can be resized and moved to some locations on the screen.

We had a situation in one of our production line that, this window sometimes only display a few part of it. Say, the top half portion only.
We had a research on this situation and we have done so many reproduction and finally we came to know that, the problem occurs in Window10 LTSB environment. Not in LTSC environment.
We have checked the messages which are received in both environment using WinSpy and it is same on both cases.

The height of the window is checked using WinSpy and it is big.
Say, if the height of the window is 100pixel. The DC draws only some portion. Say 20pixel.

One point is that, the whole drawing of this window is done in OnEraseBkgnd.
We are planning to move the whole drawing to OnPaint(), but, we have a situation to identify the cause before changing the production line.
It would be very thankful if you can help us on finding the root cause of this issue.
Can it be a known issue of LTSB environment ?


BOOL InfoDisplayWindow::OnEraseBkgnd(CDC* pDC)
{
    CBitmap m_bitmap; // Offscreen bitmap
    CBitmap* m_oldBitmap; // bitmap originally found
    CRect m_rect; // Rectangle of drawing area.

    HDC hDC = CreateCompatibleDC(pDC->m_hDC);
    CDC* pTmpDC = CDC::FromHandle(hDC);
    pDC->GetClipBox(&m_rect);
    m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
    m_oldBitmap = pTmpDC->SelectObject(&m_bitmap);
    pTmpDC->SetWindowOrg(m_rect.left, m_rect.top);

    CRect rc;
    GetClientRect(&rc);
    pTmpDC->FillSolidRect(&rc, COLOR_KEY); // Black color

    DrawFunction();// Text is displayed in this function

    CPen pen(PS_SOLID, SOLID_BORDER_WIDTH, BORDER_COLOR);
    CPen *old_pen = pTmpDC->SelectObject(&pen);

    // Drawing the 4 boarders of the window using red line.
    pTmpDC->MoveTo(rc.left, rc.bottom - 1);
    pTmpDC->LineTo(rc.left, rc.top);
    pTmpDC->LineTo(rc.right - 1, rc.top);
    pTmpDC->LineTo(rc.right - 1, rc.bottom - 1);
    pTmpDC->LineTo(rc.left, rc.bottom - 1);
    pTmpDC->SelectObject(old_pen);

    // Copy the offscreen bitmap onto the screen.
    pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
      pTmpDC, m_rect.left, m_rect.top, SRCCOPY);
    //Swap back the original bitmap.
    pTmpDC->SelectObject(m_oldBitmap);

    return TRUE;
}

Visual studio c++ 2019 debugger stop automatically

$
0
0

HelloI am testing functions of a SMART CARD DLL under Windows 10.I use the header <winscard.h> and the lib "winscard.lib"The debug suddenly stops on the second pass on the function and it's very bizarre and I don't understand why?


App_console_test_fonction_dll.exe' Win32 : Chargé 'D:\source DLL pour PU V2_3\generic dll nf4\App_console_test_fonction_dll - MBCS\x64\Debug\App_console_test_fonction_dll.exe'. Les symboles ont été chargés.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\ntdll.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\kernel32.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\KernelBase.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\sysfer.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\advapi32.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\msvcrt.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\sechost.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\rpcrt4.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\WinSCard.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\vcruntime140d.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\ucrtbased.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\devobj.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\ucrtbase.dll'.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\cfgmgr32.dll'.
Exception levée à 0x00007FF88485A839 dans App_console_test_fonction_dll.exe : exception Microsoft C++ : unsigned long à l'emplacement de mémoire 0x000000E5BE58EBB8.
Le thread 0x3fb4 s'est arrêté avec le code 0 0x0.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\winsta.dll'.
Exception levée à 0x00007FF88485A839 dans App_console_test_fonction_dll.exe : exception Microsoft C++ : unsigned long à l'emplacement de mémoire 0x000000E5BE8FF9A8.
'App_console_test_fonction_dll.exe' Win32 : Chargé 'C:\Windows\System32\kernel.appcore.dll'.
Le thread 0x2e60 s'est arrêté avec le code 0 0x0.
Le thread 0x6c0 s'est arrêté avec le code 0 0x0.
Le thread 0x3ec8 s'est arrêté avec le code 0 0x0.
Le thread 0x3de8 s'est arrêté avec le code 0 0x0.

The program '[0x24E4] App_console_test_fonction_dll.exe' stopped with code 0 0x0.

Thank you for your help, it's urgent ....

Viewing all 15302 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>