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

C++ program compiled under Windows 10 does not work under Windows 7 (missing dlls)

$
0
0

Hi there,

when I compile an MFC program and its setup under windows 10 using Visual Studio 2010 pro and then tries to install it under Windows 7, the setup installs the program correctly but the executable does not work, and fires fatal errors like "api-ms-win-errorhandling-l1-1-1.dll is missing". However, if I compile the same program and setup under windows 7, it works like a charm whether I install it under Windows 7 or Windows 10.

Obviously, there are dependencies which are needed but not detected when the program is compiled under Windows 10?

Any suggestion appreciated...

(ok, except the obvious one which is to keep a machine running windows 7 and use it to compile the final version)

fred





C++/CLI DLL referencing MFC: mfcs140d.lib(dllmodul.obj) : error LNK2005: DllMain already defined in msvcrtd.lib(dll_dllmain_stub.obj)

$
0
0

I'm trying to port some old code from a C++/COM server to a managed C++ DLL so I can remove the COM later (not needed anymore), and make it easily visible to a C# project.  I figured I'd just create a new C++/CLI project, pull in the source, replace the COM interface with a static managed class, and have what I needed.  Unfortunately, it's turning out not to be that simple.  The code I'm pulling in used some MFC classes, so I needed MFC support.  This means my new DLL project has /clr, as well as MFC (shared DLL).  When I try to link the project, I get this error:

mfcs140d.lib(dllmodul.obj) : error LNK2005: DllMain already defined in msvcrtd.lib(dll_dllmain_stub.obj)

Poking around the internet, I've found a few suggestionson what to change, but so far nothing has worked.  I've tried:

  • Setting msvcrtd.lib, mfcs140d.lib, and mfc140d.lib to be ignored, and then adding them in various orders to the additional libraries.  Same error.
  • Defining my own DLLMain stub, and adding the extern "C" { int _afxForceUSRDLL; } to the file.  That just made it complain that DLLMain was already defined in my file.
  • Setting the DLL project to be a resource DLL with /NOENTRY.  This actually lets the project build, but when I try to call it from a .net app, throws a debug assert failure (_CrtIsValidHeapPointer). And a Type Exception (System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.). 

The issue seems to be with including MFC support, since if I take this out, I can get at least some of the project to build and be callable, but removing all of the MFC in this project is way more work than I want to put in on this project, and defeats the purpose of reusing code that's already been tested.  If I'm rewriting that much, then I'm rewriting the whole project.  Is there a way to get past this build error and get things to link? 


Problem with MSAA when we access browsers as "Run As Administrator"

$
0
0

Hi All,

I am using MSAA (Microsoft Active Accessibility) methodology for enumerating browser windows (mostly browsers like IE, Chrome and Mozilla) to get some values. My project is with Visual C++ and the exe file (example: myApp.exe)  having only user privilege. When we access browsers as normal (without "Run As Administrator"), then my exe file is able to enumerate the browser window. But the issue is like; when we access the browsers as "Run As Administrator", then my exe file is not able to enumerate the browser window; and the issue is with user privilege. So there is any particular methods to overcome this problem like, we can enumerate browser window (accessing "Run As Administrator") from user privileged exe file.

Any useful help is much appreciated.

Thanks,

R-VR

GDI+ Display JPG

$
0
0

Hi all,

I am new in Visual C++ and GDI+.

I am currently using VC++ express to display a jpg file.

I basically, copy from PSDK example and paste it on my program as follow:

WM_paint:

Image myImage(L"Climber.jpg");
myGraphics.DrawImage(&myImage, 10, 10);

It didn't even compile. I am sure, I must have done something incorrectly or not doing something else in the first place.

All other example I see in the internet gave similar method.

Can anyone let me know how to at least display a JPG ?

Regards,

Alexon Jong

 

Does this function have undefined behavior?

When I click local windows debugger the program freezes.

$
0
0
I have a problem: when i click local windows debugger the program starts loading and then it freezes, but in the bottom left corner its saying that the build is succeed. Please help!

Fatal Error C1510

$
0
0
Hi. I just installed Visual Studio Community 2015, and decided to try a simple Hello world program, and I get this error: Could not load language resource clui.ddl. My current OS is Windows 10. Any help would be appreciated.

Printing command line arguments (what am I missing)?

$
0
0

Trying to get my feet wet in C++ (and refreshing my C knowledge).

#include "stdafx.h"
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[]) { for(int cnt=0;cnt<argc;cnt++) { printf("Argument[%d]: %s\n", cnt, argv[cnt]); } getchar(); return 0; }

Compiled in VS2012.

Why does the above print the below (only the first character of each argument)?

C:\Users\sterretje\Documents\3_Development_Cpp_Fun\FunctionPointerDemo\Debug>FunctionPointerDemo.exe abc
Argument[0]: F
Argument[1]: a

C:\Users\sterretjeDocuments\3_Development_Cpp_Fun\FunctionPointerDemo\Debug>

If I create the 'standard C' version of the above (on a Linux box), it works as expected.

Using Unicode DLL in a non unicode MFC application

$
0
0

Hello All,

I am having an Non Unicode MFC application (Charset: Multibyte). I have to use third party DLL which is available only in Unicode version (Charset: Unicode). Now I am not sure whether using static linking third party unicode DLL in non unicode application will create any issue. What is the suggested way to use unicode DLL in an non unicode MFC application.

Thanks and Regards,

Hari

Visual Studio 2015 intelisense is too slow

$
0
0

hello. I'm using unreal engine4 and c++ 

when I type any letter, itelisense list is not appear.

over 10seconds later , the lists are appear.

it is too slow. 

How can I fix this?

thank you

USING OLE32.DLL

$
0
0
Programming in C++ used as a Application32 with MFC. When I execute the program all runs fine except I need to use the debugger to step through the program to detect it reading the wrong data in an array. However, when I start the debugger and go to the cursor location, I immediately get a error, says "unhandled exception in Program.exe, get an access violation at 0x0000005: in ole32.dll" Anybody have ideas how to resolve and why it is happening? Sid Kraft

Property Indexing broken from VS2008 to VS2013?

$
0
0

In the VS2008 code for some class, I have:

class someclass

array<String^>^ STRLIST = array of strings

property array<String^>^ strList
{
array<String^>^ get() {return STRLIST;}
}

Then elsewhere when I wanted a string out of that list, I would just write:

int index = somenumber;

String^ str = someclassInstantiated->strList[index];

So you see I never had to explicitly write out the indexer in the property of the class; someclass->strList returns the array of String and then the [index] would index that result and return the String there automatically.

The code still compiles in VS2013, but the editor underlines in red the word "someclass" in the code last line above and the pop-up says there is an error.  The code section still runs OK.

So then I changed the class to have the following:

property array<String^>^ strList
{
array<String^>^ get() {return STRLIST;}
}

property array<String^>^ strList[int]
{
String^ get(int index) {return STRLIST[index];}
}

The red-underlined code in the editor for the other code then goes away for a minute, and then comes back.  The popup for the red underline says "Error: Can't initiate String^ from Object^".

Now as I said this code compiles fine with or without the added explicit indexer code for the property, and runs fine.

But now another problem:

In another class I have a 2-D array.

class someclass2

array<double,2>^ DBARRAY = gcnew array<double,2>(somesize,somesize);

Then the property is:

property array<double,2>^ doubleArray
{
array<double,2>^ get() {return DBARRAY;}
}

So then in code using this class, to get an element from the array in the class I would just write:

double value = someclass2Instantiated->doubleArray[index1,index2];

Again, I never had to explicitly write out an indexer.  The red-underline error shows up in the VS2013 text editor saying there is an error there, but the compiler doesn't report an error.  However, this time, the values returned are not correct, even though the code seems to run OK.

If I write out an indexer for this property, then I have:

property array<double,2>^ doubleArray
{
array<double,2>^ get() {return DBARRAY;}
}

property double doubleArray[int, int]
{
double get(int index1, int index2) {return DBARRAY[index1,index2];}
}

This should correct the error being reported by the text editor, but it doesn't.  Actually I haven't run the code to see if at least the values being returned are OK.  And actually I used to set element values the old way too:

someclass2Instantiated->doubleArray[index1,index2] = 2.22;

But now you might think it requires the class property to have:

property double doubleArray[int, int]
{
double get(int index1, int index2) {return DBARRAY[index1,index2];}

void set(int index1, int index2, double value)  {DBARRAY[index1,index2]=value;}

}

So, what am I actually supposed to do here?  And why does the editor keep underlining the code saying there is an error when there really isn't one?


SetCurrentDirectoryW won't Drop to C:\ with ".." or "."

$
0
0

Hi there,

Developing an application which creates and removes folders with SetCurrentDirectoryW andRemoveDirectoryW rather well, excepting on the final deletion of the folder:

"C:\myfolder"

GetCurrentDirectoryW still flags the current directory as in "myfolder" after the SetCurrentDirectoryW (L".") or SetCurrentDirectoryW (L"..") call from there. "myfolder" was created with CreateDirectoryW

Using SetCurrentDirectoryW (L"\\\\\?\\C:\\") worked however.

Insights appreciated.

Edit: WRT the question in this post, are there any other Win APIs that can deal with the navigation of 32k path names?



A natural, B flat, C sharp, D compile






find crash location in my code

$
0
0

Visual Studio 2010, C++, MFC

An app has been crashing with _com_error unhandled exception at location 0XDEADBEEF.  For what ever reason the stack display in VS says the stack is not valid and will not let me work back to the code that was running when the exception was thrown.

Question

How do I take that address: 0XDEADBEEF and find where in my code the app was running at the time of the crash.

Edit, the real address, one of several, is 0x002ddd64.  I made up DEADBEEF because I was searching from home and wrote this question there rather than at work where many of my search results are blocked by government fire walls.  My apologies for throwing in that confusion factor.

Notes

I have performed some searches with topics such as:  "find executable address in application" with no productive results.

Thank you for your time.


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



Mixed programing

$
0
0

hello

i use intel compiler visual stdio(intel parallel 2015) to compile my project

console ( c source ) #include <stdio.h> #include <stdlib.h> //#include <conio.h> #include <string.h> //#define readfile readfile_ extern void readfile(char*, int*); int main() { int n, count; char Fname[9]; char Name[10]; strcpy(Fname,"AMIN.for"); fprintf( stderr, "%s\n", Fname); readfile( Fname, &n, strlen(Fname) ); fprintf( stderr, "n = %d\n", n); // fprintf( stderr, "%s\n", Name); return 0; } subroutine ( Lib fortran ) subroutine readfile( fname1, m ) character fname1*(*) integer m integer iounit,i iounit=15 write(*,*) fname1 c10 format (a9) open(iounit,file = fname1,action='read') read (iounit,*) m c20 format (i10) write(*,*) m close(iounit) return end subroutine

this is my project and i don't have a problem

in this line i have a qestion

readfile( Fname, &n, strlen(Fname) );

i want to change line 

readfile( Fname, &n );

is it possible? how to call without lenght character or how to calling convert to run and compile it correctly?

how to change setting vs2012 togettoit?

Special Thanks For Your Prompet Reply ( excuse me for bad spelling )


Fmshirdel





FLTK GUI: Accessing Member Functions of an Fl_Group Derrived Class through a Callback Outside of that Class?

$
0
0

Hello, I am using Microsoft Visual C++ 2010 and FLTK 1.3.

What I have done is to create an Fl_Group derived class that holds a couple Fl_Input widgets in a row in order to instance objects of that class in the main function and efficiently create the rows. This saves me some from hand-typing repetitive lines of code for each new row and works quite well.

However, I would also like to create a member function for the code that process the information in each instance's widgets, saving me from some extra hand-typed code again. And, this is proving to be more difficult/arcane of a task than I had expected, and I have yet to find a clear example of how to do this.

The main point of difficulty seems to be using a callback function from an Fl_Button class to the member function of each of the custom Fl_Group class' instances. That causes the program to crash.

Here is the basic code that I have been working with:

#include <cstdlib> #include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Widget.H> #include <FL/Fl_Input.H> #include <FL/Fl_Group.H> #include <FL/Fl_Button.H>
#include <FL/Fl_Round_Button.H> using namespace std; int studentNum = 0; char nums[100]; char ftotal[50]; class InputRow: public Fl_Group { public: //Create the widget pointers Fl_Input *box1; Fl_Input *box2; //Contructor InputRow(int x, int y, int w, int h, const char *l=0) : Fl_Group(x,y,500,500,l) { //Load the widget pointers with widget classes box1 = new Fl_Input(x,y+10,w,h,NULL); box1->maximum_size(3); box1->value(0); box2 = new Fl_Input(x+50,y+10,w,h,NULL); box2->maximum_size(3); box2->value(0); } //Process the information in the widget by sending their values to an array for further processing. void process (Fl_Widget *o, void*) { Fl_Group *g = (Fl_Group*)o; Fl_Input *a = (Fl_Input*)g->child(0); Fl_Input *b = (Fl_Input*)g->child(1); //Load widget values to integers. int num1 = 0; int num2 = 0; num1 = atoi(a->value()); num2 = atoi(b->value()); //Perform math. int total = 0; total = num1 + num2; //Send the result to an array. char holder[5]; itoa(total,&holder[0],10); for(size_t c=0; c<strlen(holder); c++) { nums[studentNum] = holder[c]; studentNum++; } } //"Wrapper" necessary for accessing the member function in C++ classes?? static void staticProcess(Fl_Widget *o, void* userdata) { InputRow *w = (InputRow*)userdata; w->process(o,userdata); } } *ir1, *ir2; //Forward declaration of object instances. void initArrays() { for(int c=0; c<100; c++) {nums[c]=0;} for(int c=0; c<50; c++) {ftotal[c]=0;} } void calc(Fl_Widget* o, void*) { initArrays(); Fl_Group *g1 = (Fl_Group*)o->parent()->child(3); Fl_Group *g2 = (Fl_Group*)o->parent()->child(4); studentNum = 0; g1->callback(InputRow::staticProcess); g1->do_callback(); studentNum = 5; g2->callback(InputRow::staticProcess); g2->do_callback(); //Do math. int num1; int num2; num1 = atoi(&nums[0]); num2 = atoi(&nums[5]); int total = num1 + num2; //Send to display. itoa(total,&ftotal[0],10); Fl_Input *display = (Fl_Input*)o->parent()->child(5); //Arrive at Fl_Input on top level and link to an Fl_Input pointer. display->value(&ftotal[0]); //Send the value of the Fl_Group's Fl_Input widget to the upper level Fl_Input widget's value. } int main() { Fl_Window *win = new Fl_Window(500,500,"Button Values");{ Fl_Round_Button *b1 = new Fl_Round_Button(50,50,15,15); b1->set(); Fl_Input *i1 = new Fl_Input(70,50,40,20); i1->box(FL_BORDER_FRAME); i1->color(FL_BLACK); i1->set_output(); Fl_Button *set = new Fl_Button(50,70,40,20,"Set"); //Instances of a group of widgets InputRow *ir1 = new InputRow(50,90,40,20,NULL); InputRow *ir2 = new InputRow(50,110,40,20,NULL); Fl_Input *display = new Fl_Input(50, 160, 40, 20); Fl_Button *calculate = new Fl_Button(50, 180, 60, 20, "Process"); calculate->callback(calc); } win->end(); win->show(); return (Fl::run()); }

The program compiles, but pressing the "Process" button causes it to crash.

The error is:
"Unhandled exception at 0x00a01596 in buttons.exe: 0xC0000005: Access violation reading location 0x00000054."
In Autos, it lists "this".
In the Call Stack, it lists "Buttons.exe Fl_Input::value().
And it opens the Fl_Input.H in the IDE window.

I am not sure which line it is crashing on in the main.cpp.

How can I call the Fl_Group derived class's member function through a callback for each object instance?

counting pixels

$
0
0

Hi there. I give the community the following code and I would like to ask you if you have any idea on how to count the number of pixels of the circle. Thanx!!!!

#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include <windows.h>
#include <cmath>

int x, y, p;

void plotcircle(HDC mydc, int xc, int yc, COLORREF COLOR);

void main()
{
//Get a console handle
HWND myconsole = GetConsoleWindow();
// //Get a handle to device context
HDC mydc = GetDC(myconsole);

COLORREF COLOR = RGB(255, 120, 0);

int xc, yc, r;
x = 0;

cout<< "\nEnter x pos,y pos and radius" << endl;
cout << "x: ";
cin >> xc;
cout << endl <<"y: ";
cin >> yc;
cout << endl << "radius r: ";
cin >> r;

y = r;
p = 1 - r;

while (x < y+1)
{
plotcircle(mydc, xc, yc, COLOR);
if (p < 0)
{
++x;
p += 2 * x + 1;
}
else
{
++x;
--y;
p += 2 * (x - y) + 1;
}
}
system("pause");
}

void plotcircle(HDC mydc, int xc, int yc, COLORREF color)
{
SetPixel(mydc, xc + x, yc + y, color);
SetPixel(mydc, xc + y, yc + x, color);
SetPixel(mydc, xc + x, yc - y, color);
SetPixel(mydc, xc + y, yc - x, color);

SetPixel(mydc, xc - x, yc - y, color);
SetPixel(mydc, xc - y, yc - x, color);
SetPixel(mydc, xc - x, yc + y, color);
SetPixel(mydc, xc - y, yc + x, color);
}

Does MSVC/Win32 guarantee function start address is aligned

$
0
0
This question is about hotpatching. The core of hotpatching is to
replace the first two bytes instruction with a two bytes short
jump instruction. Microsoft guarantees the first instruction of a
hotpatchable function is at least two bytes. [1] Let's call it
hotpatch point [2].

To ensure the replacing operation is an atomic operation, the
address of the hotpatch point must be at least 16-bit aligned,
MSDN says nothing about this.

So my question is: Does MSVC/Win32 guarantee function start
address is aligned ?

Aman


Am I interpreting Visual Studio assembly output correctly?

$
0
0

I was curious as to the difference in overhead, if any, between the following three initializations of a float.

// Entry point of the application
int main()
{
	float test1(0.1f);

	float test2 = 0.1f;

	float test3;
	test3 = 0.1f;

	return 0;
}

I threw in some breakpoints and viewed the assembly output:

	// test case 1
	float test1(0.1f);
002F139E  movss       xmm0,dword ptr ds:[2F5858h]
002F13A6  movss       dword ptr [test1],xmm0

	float test2 = 0.1f;
002F13AB  movss       xmm0,dword ptr ds:[2F5858h]
002F13B3  movss       dword ptr [test2],xmm0

	float test3;
	test3 = 0.1f;
002F13B8  movss       xmm0,dword ptr ds:[2F5858h]
002F13C0  movss       dword ptr [test3],xmm0  

Am I right in concluding from this that each statement has exactly the same overhead since the assembly is the same for each instruction(s)? It seems in particular the compiler has optimized the third test. Is this correct?

Also, is this the correct way to go about comparing operation A to operation B?

Many thanks!




How to cancel task in parallel_for_each?

$
0
0

I follow the example on https://msdn.microsoft.com/en-us/library/ee309910.aspx

But whenever I throw exception to cancel the tasks, it will not stop at my catch statement.  I validated the compile flag as /EHsc for that module, but whenever it throw the exception, it always jump to the system exception eh\throw.cpp.

I just wonder how should I fix it?

I copied exact source code from the sample

// Searches for a value in the provided tree object. 
template<typename T>
void search_for_value(tree<T>& t, int value)
{
   try
   {
      // Call the for_all method to search for a value. The work function 
      // throws an exception when it finds the value.
      t.for_all([value](const tree<T>& node) {
         if (node.get_data() ==value)
         {
            throw&node;
         }
      });
   }
   catch (const tree<T>* node)
   {
      // A matching node was found. Print a message to the console.
      wstringstream ss;
      ss << L"Found a node with value "<<value<< L'.' << endl;
      wcout << ss.str();
      return;
   }

   // A matching node was not found. Print a message to the console.
   wstringstream ss;
   ss << L"Did not find node with value "<<value<< L'.' << endl;
   wcout << ss.str();  
}

int wmain()

   // Build a tree that is four levels deep with the initial level  
   // having three children. The value of each node is a random number.
   mt19937 gen(38);
   tree<int> t = build_tree<int>(4, 3, [&gen]{return gen()%100000; });

   // Search for a few values in the tree in parallel.
   parallel_invoke(
      [&t] { search_for_value(t, 86131); },
      [&t] { search_for_value(t, 17522); },
      [&t] { search_for_value(t, 32614); }
   );
}

Thanks,

Steve

Viewing all 15302 articles
Browse latest View live