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

how to convert Visual Studio 2010 C++ .EXE project that shows a window into .DLL project that still shows same window, on Windows-7 Pro

$
0
0

I have a Visual Studio C++ .EXE project that opens a window and display a live, grayscale image OK.
I changed project to .DLL so imagine generation methods can be called (COM) by a C# project, and this works OK.

How can I, for debugging, have the DLL also run its normal windows dialog, to open and display its window to show live image, just like the .EXE does?

Project Configuration:   "Use MFC in a Shared DLL", "Not Using ATL", "Common Language Runtime Support (/clr)"

I've tried an access function in DLL that does:  "theApp.InitInstance();"
but it crashes DLL (debug assert) at:  "INT_PTR nResponse = dlg.DoModal();"

(Frame display rate will be under 60 frames per second.  The .EXE or .DLL generates frame in a buffer that is 512 pixels wide, 512 pixels high, with 8 to 32 bits per pixel, depending on settings.)

 


software developer


Convert std::string to char[]

$
0
0

//My function is for converting std::string to char[]

void stringConvertToChar(string& str,char arr[]) //To convert std::string to char[] { char *y = new char[str.length() + 1]; strcpy_s(y, str.c_str()); strcpy_s(arr,y); return; }

error: strcpy_s doe'snt accept 2 arguments.

i used strcpy_s as when i used strcpy(), the compiler was giving a warning of depriciated strcpy.

Please help!


"fatal error C1083: Cannot open include file" while compiling for x64 architecture on Windows 7

$
0
0

Hi everyone,

  I recently installed Visual Studio 2012 Pro and compiled boost library with it (succesfully). Then I decided to compile some example with boost. At first everything went smooth: Win32 compiled both in release and debug version. Unfortunately this was not the case when I tried to compile x64 versions... I got the following error:

1>server.cpp(38): fatal error C1083: Cannot open include file: 'boost/aligned_storage.hpp': No such file or directory

The things I checked are:

  1. The file is in correct place (exact location: C:\dev\include\boost\boost\aligned_storage.hpp). If it hadn't been there then the Win32 version wouldn't have compiled.
  2. I have set the environment variable INCLUDE as "C:\dev/include;C:\dev/include/boost" .
  3. My "VC++ Directories" looks like this:while "C/C++ -> General" like this
  4. I generated the x64 configuration using the instruction here: How to: Configure Visual C++ Projects to Target 64-Bit Platforms .

This is the code:

//
// server.cpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//


#ifndef WINVER                  // Minimum platform is Windows 7
#define WINVER 0x0601
#endif

#ifndef _WIN32_WINNT            // Minimum platform is Windows 7
#define _WIN32_WINNT 0x0601
#endif

#ifndef _WIN32_WINDOWS          // Minimum platform is Windows 7
#define _WIN32_WINDOWS 0x0601
#endif

#ifndef WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN
#endif

#ifndef NOMINMAX                // Use the standard's templated min/max
#define NOMINMAX
#endif

#ifndef _USE_MATH_DEFINES       // We do want PI defined
#define _USE_MATH_DEFINES
#endif

#include <cstdlib>
#include <iostream>
#include <boost/aligned_storage.hpp>
#include <boost/array.hpp>
#include <boost/bind.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/asio.hpp>

using boost::asio::ip::tcp;

What did I omit or messed up?

Best regards and thank you in advance
Lehhu


nickel & dime performance gains

$
0
0

In my Win32 shell, its designed to print results from any task. Makes it a native Windows program and looks better than a console project.

So far...

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {...}


is now well past 1000 lines of code to handle all possible events needed to be able to scroll up and down, wheel mouse and even two finger drag with a touch screen

never bothered with horizontal stuff as TextOut is easily over 132 columns which is more than needed for any print outs

one technique I like, is the embedded argument.

SetScrollRange (hwnd, SB_VERT, 0, activelist.size()*rowheight, TRUE);

this way the result is still on the stack ready for the windows call

sometimes such calls can spawn a monstrous amount of code depending on the number of arguments etc.

so it pays to keep everything on the stack and not have to move stuff on and off all the time



Corsair Carbide 300R with window & Corsair TX850V2 70A@12V

Asus M5A99FX PRO R2.0 CFX/SLI & AMD Phenom II 965 C3 Black Edition @ 4.0 GHz & G.SKILL RipjawsX DDR3-2133 8 GB 

GTX 260 SLI 216 core (GT200 Tesla) & Asus PA238QR IPS LED HDMI DP 1080p

ST2000DM001 & Windows 7 x64 Enterprise

Microsoft Wireless Desktop 2000 & Wacom Bamboo CHT470M

Place your rig specifics into your signature like I have, makes it 100x easier to understand!


Hardcore Games, Legendary is the Only Way to Play

Application using SQL

$
0
0
My application creates and uses some databases in SQL. I have SQL in my computer and it works fine in my computer, but will it work on another computer which dosen't have SQL

how can i trace every function call?

$
0
0

hi i,

i'm new to VC2010. Given the source code, i'm supposed to quickly understand the behaviour the program.

now how can i tweak the build configuration, so whenever it enters or leaves a function call, one message indicating it is recorded. after that, i can review the recorded messages to analyze the RUNTIME behavior the program.

thanks,

Andrew


Andrew
BI, Data Mining, Analytical CRM

Implement Winsock interprocess communication to synchronize a vector?

$
0
0

Using C++ I would like to setup interprocess communication using sockets (Winsock) between a single server and several client processes.

The server and all client processes will be running on the on the same Windows 7 computer.

The intention is that a std::vector of some hundreds of std::string data elements will be held by the server and transmitted to each client.

From time-to-time the vector held by the server will be extended with further data elements and the extra data will need to be transmitted to each client.

The result being that the client has an updated copy of the vector held on the server; the server and clients vectors will be synchronized.

Can anyone provide links to examples of how to do this, relevant reference materials or a demonstration code example?

What I'm trying to do is fairly simple, implementing it for the first time is not! Any help greatly appreciated.


Visual C++ Error : Uninitialised variable

$
0
0
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

void display(char *, int);

int main()
{
	char *ip;
	char *op[4];
	int j, i=0, num=0, count[4]={0, 0, 0, 0};
	
	printf("Enter the response of GSM Module : ");
	//gets(ip);
	scanf_s("%s",ip);
	printf("%s",ip);
	//printf("Hello");
	for(i;;i++)
	{
		printf("%c",*(ip+i));
		if(*(ip+i)=='"')
		{
			op[num]=ip+i+1;
			for(j=i+1;;j++)
			{
				printf("%c",*(ip+j));
				if(*(ip+j)=='"')
				{
					count[num]=j-i-2;
					num+= 1; 
					i=j;
					break;
				}
			}
		}
		if(*(ip+i)=='\n')
			break;
	}
	///printf("ip : %d Count : %d op : %d difference : %d\n",ip, count, op, (op-ip));
	printf("\nSender's Number : ");
	display(op[0],count[0]);
	printf("\nMessage Status : ");
	display(op[1],count[1]);
	printf("\n Date & Time : ");
	display(op[2],count[2]);
	printf("\nReceived Message : ");
	display(op[3],count[3]);
	_getch();
	return 0;	
}

void display(char *dip, int c)
{
	int i;
	for(i=0;i<=c;i++)
		printf("%c",*(dip+i));
}

In this code, ip is a character pointer. Generally in C variables without initialisation is normal. But here it gives the error of uninitialised variable ip used.

I have tried to initialise ip by setting it equal to NULL, but it also gives me another error.

Earlier I have successfully compiled and run a code without initialisation and by modifying that code only, I generated this code.

Please suggest me what to do, as I can't find any problem in my code.


Distinguish between launch using command line and double-click

$
0
0

Hi There,

How would you determine whether a program is double-clicked or invoked from the command line? I am looking for vc++ way of achieving it!

Thanks | Abhishek

Separating C++ source program into separate files

$
0
0
I have built a fairly complex VS C++ program which works perfectly. My problem is that the single source file is fairly long and, since I am planning to add further features, it would be convenient to separate it into more than one .cpp file. I guess I just don't know the correct procedure for doing this. I wrote a .h file that has all the class definitions etc. in it, but when I break up my source file into, say, two .cpp files and#include the header file in each, the compiler complains about multiple definitions; if I don't#include it, the compiler says it doesn't know what I am talking about. I understand both complaints but don't know how to get out of this situation. I would appreciate some help.

gabriel weinreich

Cannot Use Resources In Windows Forms ( Visual C++ ) .

$
0
0

This question is now solved . I was messing around !

Thanks to all replies .

MFC modeless dialog dll can't show tooltips normally

$
0
0

Hello,

      I met a question about the tooltips in modeless dialog dll.

      I use the method to set a hook in my dll. MSDN Link:"The TAB key doesn't move input focus from one control to another. Pressing the arrow keys or accelerator keys in the modeless dialog box or propertysheet window has no effect."

      But the result cann't meet my requirement. The tool tip just show a flash, not more then one second. I want them as model dialog's tooltip's do. when the mouse leave the tool tips disappear.

      I have try all methods I thought which could fix it, but in vain. Such as "Sleep(100)".

      Maybe the hook interrupt by Onpaint()? I don't know.

      I have no idea about what is the problem. Could you tell me what the problem is?  

      Thank you very much in advance.

How to get Excel comment using Visual C++(MFC)?

$
0
0

hello everyone:

How to get Excel comment using Visual C++(MFC)?

Part of mycode is:

#include "CApplication.h"
#include "CWorkbooks.h"
#include "CWorkbook.h"
#include "CWorksheets.h"
#include "CWorksheet.h"
#include "CRange.h"
#include "CComment.h"
#include "CComments.h"

CApplication m_app;                         
    CWorkbook m_book;                        
    CWorkbooks m_books;                      
    CWorksheet m_sheet;                       
    CWorksheets m_sheets;                 
    CRange m_range;                        
    CRange m_cell;                             
    CComment m_comment;                 
    CComments m_comments;

m_app.CreateDispatch(_T("Excel.Application"), NULL);

m_books.AttachDispatch(m_app.get_Workbooks(), TRUE);

    if (m_lpDisp)
    {
        m_book.Close( covFalse, COleVariant(m_strPathName), covOptional );
        m_books.Close();
        m_lpDisp = NULL;
    }

    m_lpDisp = m_books.Open( m_strPathName,
        _variant_t(vtMissing), _variant_t(vtMissing), _variant_t(vtMissing), _variant_t(vtMissing),
        _variant_t(vtMissing), _variant_t(vtMissing), _variant_t(vtMissing), _variant_t(vtMissing),
        _variant_t(vtMissing), _variant_t(vtMissing), _variant_t(vtMissing), _variant_t(vtMissing),
        _variant_t(vtMissing), _variant_t(vtMissing) );

    if (!m_lpDisp)
        return FALSE;

    m_book.AttachDispatch(m_lpDisp, TRUE);
    return TRUE;

if (!m_lpDisp)
        return 0;

    m_sheets.AttachDispatch(m_book.get_Worksheets(), TRUE);

    m_iSheetNum = m_sheets.get_Count();
    return m_iSheetNum;

m_sheet.AttachDispatch(m_sheets.get_Item(_variant_t(strSheetName)),TRUE);

try
    {

        m_range.AttachDispatch(m_sheet.get_UsedRange(), TRUE );

        m_range.AttachDispatch( m_range.get_Rows(), TRUE );
        iUsedRowNum = m_range.get_Count();

        m_range.AttachDispatch( m_range.get_Columns(), TRUE );
        iUsedColumnNum = m_range.get_Count();

        m_range.AttachDispatch( m_sheet.get_Cells(), TRUE );

        vtr_Data.clear();
        for (i=1; (i<=iUsedRowNum) && m_bWork; i++)
        {
            str_line.clear();
            for(j=1; j<=iUsedColumnNum; j++)
            {
                m_cell.AttachDispatch( m_range.get_Item( COleVariant( (long)(i)), COleVariant( (long)j ) ).pdispVal, TRUE );
                varItemName = m_cell.get_Value2();
                if(varItemName.vt == VT_BSTR)  
                {   
                    str=varItemName.bstrVal;
                }
                else if(varItemName.vt == VT_R8)
                {
                    str.Format(_T("%d"),(int)varItemName.dblVal);
                }
                else if(varItemName.vt == VT_EMPTY)
                {
                    str = _T("");
                }

                str_line.push_back(str);
            }

            vtr_Data.push_back(str_line);
        }
    }
    catch (...)
    {
        return ERROR_EXCEPTION;
    }

How to dispose CWinFormsControl correctly

$
0
0

Hi Experts,

we have several ActiveX controls which are used as glue code between our Win32 application and newer .NET controls.

Lately I analyzed a GDI leak and stumbled over still rooted .NET controls which are hosted by CWinFormsControl instances.

My Question: The CWinFormsControl has no destructor nor does the MSDN contain detail information about what actions have to be performed when a CWinFormsControl instance should be correctly freed (no GDI, User-Object) leaks.

(Note: Currently I dispose the control that is encapsulated by CWinFormsControl. The CWinFormsControl instance is a member of an object so my initial expectation was that cleanup tasks would be performed in the destructor of CWinFormsControl. As mentioned before CWinFormsControl has no dtor... so what are the correct cleanup tasks: Call Dispose, DestroyHandle and release the reference with Detach ?!)

Thanks!

After Upgrade VS2010 to VS2012 missing projects porperty page

$
0
0

I just started to test a migration of our solution from VS 2010 to VS 2012.

Unfortunatly lots of c++ projects in the solution are failing to build.

I wanted to check the configuration property pages, but I can't find them.

Can someone help me out?

Kind Regards,

Marliese


Connect Function always succeeds

$
0
0
I'm beginner in winsock programming and i witnessed a peculiar behaviour of the connect function to establish a socket connection.The socket function succeeds even though there's no valid host in the network .For example there's no host with the ip 192.168.4.38 in our network but the connection to the call still succeeds and i tried giving ip address that's outside our network for example1.1.1.1 and it still succeeded . Is there a reason or there's a bug in the api.i have posted the code below 
#ifndef UNICODE
#define UNICODE
#endif

#define WIN32_LEAN_AND_MEAN

#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>

// Need to link with Ws2_32.lib
#pragma comment(lib, "ws2_32.lib")

//char ip[16]={};

int main()
{
    //----------------------
    // Initialize Winsock
    WSADATA wsaData;
    int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != NO_ERROR) {
        wprintf(L"WSAStartup function failed with error: %d\n", iResult);
        return 1;
    }
    //----------------------
    // Create a SOCKET for connecting to server
    SOCKET ConnectSocket;
    ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (ConnectSocket == INVALID_SOCKET) {
        wprintf(L"socket function failed with error: %ld\n", WSAGetLastError());
        WSACleanup();
        return 1;
    }
    //----------------------
    // The sockaddr_in structure specifies the address family,
    // IP address, and port of the server to be connected to.
    sockaddr_in clientService;
    clientService.sin_family = AF_INET;
    clientService.sin_addr.s_addr = inet_addr("1.1.1.1");
    clientService.sin_port = htons(80);

    iResult = connect(ConnectSocket, (SOCKADDR *) & clientService, sizeof (clientService));
	printf("The socket connect status  %d ",iResult); // always 0 indicating success 
    if (iResult == SOCKET_ERROR) {
        wprintf(L"connect function failed with error: %ld\n", WSAGetLastError());
        iResult = closesocket(ConnectSocket);
        if (iResult == SOCKET_ERROR)
            wprintf(L"closesocket function failed with error: %ld\n", WSAGetLastError());
        WSACleanup();
        return 1;
    }

    wprintf(L"Connected to server.\n");

    iResult = closesocket(ConnectSocket);
    if (iResult == SOCKET_ERROR) {
        printf("\n socket Connection failed ");
        WSACleanup();
        return 1;
    }

    WSACleanup();
    return 0;
}




regex header file not found in VC 2008 Pro

$
0
0
I'm unable to use #include <regex>, it says header file not found. It is not there in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include. Isn't 2008 compiler TR1 compliant? I heard it is, but where is the regex header file?

fatal error LNK1104: cannot open file 'libpjproject.obj

$
0
0

hello guys, 

                i am facing this problem at compilation time please help me what the issue.....

                Error1fatal error LNK1104: cannot open file 'libpjproject.obj'

waiting for your valuable response.... 

  

sure

DECLARE_SERIAL & IMPLEMENT_SERIAL

$
0
0

can anybody tell me definition of DECLARE_SERIAL and IMPLEMENT_SERIAL macro ?

Mrutyunjaya

Invisible Dialog Control Flicker

$
0
0

Hello all,

   I've created a control I've placed onto a dialog (mostly for testing purposes).  The control has a transparent background.  I've added code to the dialog to draw random images in OnPaint().  I have a timer which calls Invalidate 10 times a second.  I've overridden OnEraseBkgnd on both the CDialog and the control to not erase the background to reduce flicker.  I also grab a copy of the background in the controls OnEraseBkgnd method.  When its time to draw the control, I blit the background onto a back buffer and then draw the control on top of that.  After drawing the control I blit the back buffer to the screen.  What I see is that all controls are erased in the dialog's OnPaint() method, however, every control but my custom control redraws itself without flicker.  I suspect my control is the last to be drawn.  Either my control is taking too long to draw (sometimes, not all the time) or its order in the drawing cycle causes it to be drawn too late.  I would prefer CDialog to draw on a back buffer and only blit to the screen after every control has drawn itself.  Does anyone have any suggestions to eliminate the flicker?

Thanks,


Viewing all 15302 articles
Browse latest View live


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