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

Can't change character in wchar_t string

$
0
0

I have this code:

int main()
{
    wchar_t* wch = L"One String";
    std::wstring wstr(L"Another string");
    wstr[1] = L'F';
    std::wcout << wstr << std::endl;
    wch[1] = L'U';
    std::wcout << wch << std::endl;
}


The output of wstr is OK, but when wch[1] = L'U' is reached, the program crashes. Why does it happen?


There is no knowledge that is not power.


How can I request a value and wait for the value to be returned via MFC socket classes but not using http?

$
0
0

I have an arduin microcontroller connected to my home network and it is running a UDP server.

I can successfully send data to it, using CAsynchSocket, and I can confirm it received by the microcontroller.

But there seems to be no way I can use this class to receive data back from the microntroller immediately after the request.

In fact the data arrives some time after my requesting function exits - which is useless.

I can't use any blocking loops in my requesting function because that prevents virtual void OnReceive(int nErrorCode) from being called and the data from the microcontroller will never arrive while the loop is running.

I am trying to use this to send small files between windows app and the micro controller - I can't use ftp with this micro controller

Bit masking and shifting ?

$
0
0

Can anybody can briefly explain "The Bit masking" , "Circular rotation of shifting operand". 

If possible with example source code used the mentioned methodology.

Thanks 

WCHAR pointer is null after allocation in another function

$
0
0

What I'm trying to do is to allocate the LPWSTR in another function:

#define NUM_CHARS 5

int initwch2(LPWSTR wch2);

int main()
{
    LPWSTR wch2 = nullptr;
    initwch2(wch2);
    if (wch2 == nullptr)
    {
	std::cout << "wch2 is nullptr" << std::endl;
    }
    else
    {
	std::cout << "wch2 is initialized" << std::endl;
    }
    free(wch2);
}

int initwch2(LPWSTR wch2)
{
    wch2 = (LPWSTR)malloc(sizeof(WCHAR) * NUM_CHARS);
}
However, wch2 is always nullptr. But I pass a pointer into function. Why is it null after function is gone?


There is no knowledge that is not power.

Help wanted with colliders/collision

$
0
0
Hi,

I'm pretty new to programming and am working on an entry assignement for the game development school I hope to attend this year. I need to develop a working 2d game in C++ and I'm using SFML. 

At the moment I'm stuck at working with collisions and the tilemap. So far I have a movable player object, a tilemap that loads correctly and a collision map that seems to be loading correctly. When a collision is detected, I move the player object a few pixels in the opposite direction of where the player object was moving. I'm using the width of the player object and the tile on the map that he is colliding with, and use subtraction and the like to calculate the amount of pixels to move. My goal is to stop the player object when it runs into another (solid) object. When entering the collider I want to move it out of the collider, before drawing the frame. The result is unfortunatly somewhat unexpected.... 

When the player object hits another object (in my code the player starts by falling down onto a solid object, being the ground) it keeps 'jumping' up and down for a smal amount of pixels, just above the collider. I can keep moving right and left but the player object keeps jumping up and down... 

I think there may be a problem with my code I use for this, but I fail to understand what I could be doing wrong:


if (p1.right < tileLeft || p1.left > tileRight || p1.top > tileBottom || p1.bottom < tileTop)
{
}
else
{
if (p1.bottom > tileTop && p1.bottom > tileBottom)
{
p1.rect.move(0, (-(p1.bottom - tileTop)));
p1.update();
}
else if (p1.top < tileBottom && p1.top < tileTop)
{
p1.rect.move(0, (-(tileBottom - p1.top)));
p1.update();
}
else if (p1.right > tileLeft && p1.right > tileRight)
{
p1.rect.move(-(p1.right - tileLeft), 0);
p1.update();
}
else if (p1.left < tileRight && p1.left < tileLeft)
{
p1.rect.move((tileRight - p1.left), 0);
p1.update();
}
}


Can someone point me in the right direction? Being a solution or a suggestion on how to debug this.. I'm really stuck here. Any help is greatly appreciated!


Kind regards, Jonah

PS. Here's a link to the entire code I have so far: https://gitlab.com/jonah_rutten/BOOST.git
PPS. Please forgive me if I'm not addresseing the issue correctly or if I'm not using the correct lingo.. I'm pretty new to all this and still have much to learn!

How fix: “EXEC error: WNETBASE environment variable not set” in Visual Studio?

$
0
0

I'm creating a kernel driver using VS 2013 + WDK 8.1 + DDKBUILD VERSION 3.12 FREEWARE + SDK 8.1 and comes the following error's when Build Solution:

In Error List tab:

  • error: WNETBASE environment variable not set
  • error MSB3073: The command "ddkbuild-WNET checked." exited with code -1

In Output tab:

  • EXEC error: WNETBASE environment variable not set
  • NOTE: windows  .net DDK versions supported must be build 3663 or later

So, how solve these errors?

How do you use CAsynchScoket or CSocket to connect to local IP address?

$
0
0

The following code does not work - the local IP address is 10.0.0.7 (m_strIPAddr = "10.0.0.7")

I have an arduino micontroller running as a UDP server and I can successfully send data to my arduino with a 'UDP Client Server' for windows. However I would like to be able to do the same with my windows app.

So how do I correctly use windows sockets to do this?

void CIrrigationUploaderUDPDlg::OnClickedButtonConnect()
{
	if (!m_strIPAddr.IsEmpty())
	{
		if (m_pSocket)
			delete m_pSocket;
		m_pSocket = new CIrrigationSocket();
		if (m_pSocket->Create(10002, SOCK_DGRAM, FD_READ | FD_WRITE, m_strIPAddr) == FALSE)
			DisplayError(m_pSocket->GetLastError());
	}
	else
		AfxMessageBox("Please enter the IP address of your irriigation controller!", MB_OK);
}


How to rotate bitmap/png file to draw transparent color correct by using CImage?

$
0
0

Hi All,

     I encounter a problem that for function CImage::PlgBlt could not draw the transparent color correct for rotation, it will draw transparent color with black color, the expected result is that it should ignore the transparent color.

     The following code is  to draw bitmap, the view background color is white color, and as you know the bitmap has white color as transparent color, so the code will look like:

Case 1: Correct result picture to draw bitmap by calling CImage::TransparentBlt or

CImage::Draw, we see inside bitmap border it will have transparent color, it will

ignore these pixel an not draw them.

Case 2: Wrong result picture to draw bitmap in rotation by calling CImage::PlgBlt,

here we see, it will draw transparent color with black, the is not correct, it should also

ignore it and keep it the same as background color.

So how to solve the problem that when using CImage::PlgBlt to draw transparent color

correct(ignore or not draw the pixel)?

Any suggestion is welcome.

Best regards,

Michael



IDispatch *pXlSheet, how to get hold of the safe array?

$
0
0

I've spent two hours trying to understand or get hold of a decent complete working example of how to get (not put) an array of values from an IDispatch of an Excel worksheet. Mr Google and Mr Microsoft have thousands of incomplete and confusing examples, could someone help?

Here is a piece of code which when handed a IDispatch*from an Excel worksheet correctly counts the number of items in the returned range. But how do I actually get at each individual item?

void GetCellContents(IDispatch *pXlSheet, const IID iid)
{
    // get cell which you need
    char location[255] = "A1:B4";
    OLECHAR *sOleText = new OLECHAR[strlen(location) + 1];
    mbstowcs(sOleText, location, strlen(location) + 1);

    IDispatch *pXlRange; // Get Range from Sheet
    VARIANT parm;
    parm.vt = VT_BSTR;
    parm.bstrVal = ::SysAllocString(sOleText);
    VARIANT result;
    VariantInit(&result);
    AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Range", 1, parm);
    VariantClear(&parm);
    pXlRange = result.pdispVal;

    TRACE("The result.vt is %d\n", result.vt); // turns out to be 0x09

    VariantInit(&result);
    AutoWrap(DISPATCH_PROPERTYGET, &result, pXlRange, L"Count", 0);
    TRACE ("There are %d things in this result\n",result.lVal) ; // Turns out to be 8, which seems correct

    // ...but how do I get at each item in the 2row by 4 column cells?

Apologies if it is not tidy code because I'm trying to work out how to do it...



http://www.ransen.com Cad and Graphics software

Is it possible to use C# grammer in C++ project in terms of compatiblility?

$
0
0

I want to use method through using namespace, after choosing Common Language Runtime(/clr) option.

I wanna know it is possible.

How to save my application window as an image using C++ in Visual Studio 2010

$
0
0

Dear Ms/Sr.

I'm developing a viewer application that many users use to prepare reports and presentations.

Currently they use "print screen" and mspaint to save views of what  the application shows, one by one.

I want to enable a user of the application to save the application's window "as is" by one button-click.

I work with C++, using MFC in Visual Studio 2010

Thanks!

only static data members can be initialized inside a ref class or value type

$
0
0

Hi, I've a problem with my code, i know c++ little, please be forgiven

#pragma once
#include "magazyn.h"
#include <math.h>
namespace wahadlo {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for MyForm1
    /// </summary>
    public ref class MyForm1 : public System::Windows::Forms::Form
    {
    public:
        MyForm1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
            
                
        }
    private: System::Windows::Forms::TextBox^  textBox4;
    private: System::Windows::Forms::DataVisualization::Charting::Chart^  chart1;
    private: System::Windows::Forms::Label^  label5;
    private: System::Windows::Forms::Label^  label6;
    private: System::Windows::Forms::TextBox^  textBox5;
    private: System::Windows::Forms::Label^  label7;
    private: System::Windows::Forms::Label^  label8;
    private: System::Windows::Forms::TextBox^  textBox6;
    private: System::Windows::Forms::Label^  label9;
    private: System::Windows::Forms::Label^  label10;
    private: System::Windows::Forms::Label^  label11;
    private: System::Windows::Forms::TextBox^  textBox7;
    private: System::Windows::Forms::TextBox^  textBox8;
    private: System::Windows::Forms::TextBox^  textBox9;
    private: System::Windows::Forms::ComboBox^  comboBox1;
    private: System::Windows::Forms::CheckBox^  checkBox1;
    private: System::Windows::Forms::Label^  label12;






    public:
        
        magazyn* m = new magazyn;             //HERE IS A PROBLEM

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~MyForm1()
        {
            if (components)
            {
                delete components;
            }
        }

Calling a C# DLL from MFC application

$
0
0

I have written a C# DLL before and called it's methods from an MFC application, so I know the basic concept of what to do.

But I am looking at a situation here where I want to read a XML file into an array of objects.

With what I have recently learned about the XmlSerializer it sounds that this would be right up it's street.

So my intention is to prepare a DLL library in C# that is designed to create List<MyStructure> or Map<String,MyStructure> objects from the content of the XML file.

My library will then allow you to add an entry to the list or map (which subsequently updates the XML), delete or edit.

Now my concept question ... is it possible to transfer the List<MyStructure> object in entirety to the MFC application via some library method? Is this a bad idea? Is it better that the DLL stay alive for the the duration I need it, with it's data there internally and I have methods that return just one name and structure.

So I have no code at this point, I am just trying to understand what is possible to help me decide the way forward.

Thanks.

Bether System For Music win 8 based

$
0
0

Hallo, i need a windows system based on win 8 up only use the audio support and simpli www for registry keys and download racks and software music programs or ohter drivers for audio interface and hardware synthesizers. without all the stuff use cpu and make crash the difficult music fx on trigger and fat space and kHz ect samplkerate and so on simply for music, nothing other

have someone a really important clean win 8 pro downgraded systembuild? i mean with closed all not need options like bluetooth and and and really so clean that win can use audio and internet nothing other make bithe errors or unstabile system. faktor 1 powerfull full and clean sound nonstop 8 houers a day. next day again no bugs no attacks no possible hacks

you know what i mean stabile system nonstop

thanks for support


missing acdb16.dll

$
0
0

Hi 

I just went to load my reload my Autodesk autosketch 9 disc and it says that the program cant start because acdb16.dll is missing.

Where do I find it and how do I fix the problem




Using WinInet to update database

$
0
0

I want to update a MySql database from a Windows application that is written in Visual C++. I have used the article "How to simulate a Form POST request by using WinInet" for guidance and changed it to the GET request. There were no updates made to the database.  I changed the code to use the localhost for test purposes. 

void COnlineProView::HTTPFormGetRequest(CString szFormData)
{
	CString szHeaders =
		_T("Content-Type: application/x-www-form-urlencoded");
	CInternetSession session;
	CHttpConnection* pConnection =
		session.GetHttpConnection(_T("localhost"));
	CHttpFile* pFile =
		pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,
			_T("localhost/aws.php"));
	BOOL result = pFile->SendRequest(szHeaders, (LPVOID)(LPCSTR)szFormData, szFormData.GetLength());
}

My aws.php is a simple program that prints the $_GET array. When I run my application, I don't get to see any output from aws.php in my browser. I will say that I am a complete novice at passing data via the internet so I'm not completely sure that I'm looking in the right area. I would appreciate any advice. Many thanks. 

Opening Source file

$
0
0

I want to write my own text as default each time when i open source file of new project!

#include <iostream>
using namespace std;
void main()
{

system("pause")
}

This is the data i want to see on screen every time when i open new source file in new project in my visual studio!

TIA,

Sabeel Hussain

change static font size in static text control

$
0
0

Hi, I am trying to change the font size instead of the font family, every time I have reset the font family using the below code, any better way,

CFont font;
font.CreatePointFont(6,_T("Arial"));
GetDlgItem(IDC_STATIC_TEXT)->SetFont(&font);

NaN < NaN? Visual Studio 2015 breaking change or bug?

$
0
0

Visual Studio 2013 (Update 5) and Visual Studio 2015 (Update 3) can't seem to agree on whether or not NaN < NaN.

Is this a compiler bug?  I'm under the impression that comparisons involving NaN are defined to be false.

#include <limits>
#include <cassert>

static const double n = std::numeric_limits<double>::quiet_NaN();

int main()
{
	assert( !(n < n) );
}


why is conhost.exe is running after executed a consoleApplication

$
0
0

hello everybody.

i have made a very simple console Application with visual studio 2015 and c++ console program.

#include "stdafx.h"

int main()
{
 getchar();
    return 0;
}

i have looked at the task manager, conhost.exe program will be showed after executed the console program.

i don't know not executed conhost.exe.

because i am writing a some code, the main process will be called a child console program using CreateProcess.

A number of child Console program will be between 10~200. so i don't want to execute the conhost.exe with my child process.

Viewing all 15302 articles
Browse latest View live


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