How to erase an already drawn line using GDI+ in Win32 C++ application?
`export` attribute not found
Hello,
After upgrading the compiler to v141, i am unable to use the COM c++ attribute `export`.
The compiler throws error saying - error C2337: 'export': attribute not found. Does this version of compiler not support this attribute at all ?
Thank-you for your time!
How do I upload files from C++ using curl to PHP server
Please don't give links of curl documentation or examples as they are very old and confusing
i just need a very simple example in which if i send files of type .docx or .pdf from c++ to my php script i can save them in folder on php server
CURL * curl; curl_global_init(CURL_GLOBAL_ALL); CURLcode res; string UserName = pcobj.getUserName(); string request = "UserName=" + UserName; string url = "http://localhost:8084/project/Files.php"; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.c_str()); res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_easy_cleanup(curl); } curl_global_cleanup();
and this is what i am using to try to send files from this location to my wamp server
CURL *curl;CURLcode res;
struct stat file_info;
curl_off_t speed_upload, total_time;
FILE *fd;
fd = fopen("C:\\Uni\\CV.docx", "rb"); /* open file to upload */
if (!fd)
return 1; /* can't continue */
/* to get the file size */
if (fstat(fileno(fd), &file_info) != 0)
return 1; /* can't continue */
curl = curl_easy_init();
if (curl) {
/* upload to this place */
curl_easy_setopt(curl, CURLOPT_URL,
"http://localhost:8084/Server/new_folder_name");
/* tell it to "upload" to the URL */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* set where to read from (on Windows you need to use READFUNCTION too) */
curl_easy_setopt(curl, CURLOPT_READDATA, fd);
/* and give the size of the upload (optional) */
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
/* enable verbose for easier tracing */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
else {
/* now extract transfer info */
curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
fprintf(stderr, "Speed: %" CURL_FORMAT_CURL_OFF_T " bytes/sec during %"
CURL_FORMAT_CURL_OFF_T ".%06ld seconds\n",
speed_upload,
(total_time / 1000000), (long)(total_time % 1000000));
}
/* always cleanup */
curl_easy_cleanup(curl);
}
fclose(fd);
return 0;
return status is okay but the file didn't appear in the new_folder_name folder
MFC control question?
Hi, I want to ask when using MFC, is there any 3rd party controller that supports it? eg syncfusion, telerik, ..
because I want to use more features and more modern for my project.
Currently I am only allowed to use MFC and WPF, but I do not know anything about wpf and how to link it to c ++.
Many thanks!
MFC SDI titlebar color change
I am able to change the dialog title bar color with the following:-
{
CDC* pDC = GetWindowDC();
CRect CapRct;
GetWindowRect(&CapRct);
long myFillColour = RGB(200, 0, 0);
long myTextColour = RGB(0, 0, 0);
int x1 = GetSystemMetrics(SM_CXDLGFRAME);
int y1 = GetSystemMetrics(SM_CYDLGFRAME);
int x2 = CapRct.Width() - GetSystemMetrics(SM_CXDLGFRAME);
int y2 = GetSystemMetrics(SM_CYICON) - GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYBORDER);
CapRct.left = x1;
CapRct.top = y1;
CapRct.right = x2;
CapRct.bottom = y2;
pDC->FillSolidRect(&CapRct, myFillColour);
CFont* pCurFont = GetFont();
LOGFONT lf;
pCurFont->GetLogFont (&lf);
lf.lfItalic = TRUE;
lf.lfWeight = FW_NORMAL;
lf.lfWidth = 12;
lf.lfHeight = 18;
strcpy(reinterpret_cast<char*>(lf.lfFaceName) ,"Veranda");
CFont capfont ;
capfont.CreateFontIndirect (&lf);
pCurFont = pDC->SelectObject (&capfont);
pDC->SetBkMode (TRANSPARENT);
pDC->SetTextColor (GetSysColor(COLOR_CAPTIONTEXT));
pDC->DrawText (_T("<Dialog Text>"), &CapRct, DT_CENTER | DT_VCENTER);
}
But when I apply the same in SDI application, it is giving assertion error pCurFont->GetLogFont (&lf); When debug the application found that afxwin1.inl-> CFont::GetLogFont()->{
ASSERT(m_hObject != NULL); is null, but same object exist at the time of dialog based application?
Can anybody suggest me , how to resolve the same or If there is better medium to do so. I would like to change the color of title bar including setting the font for the caption of title bar and close button should be available as well
Launching 64-bit application in C++
Hi,
I have an 64-bit exe which am trying to launch it through 32-bit application running on 64-bit Windows 10 OS.
Is any one have a solution to launch the 64-bit exe from 32-bit application using some CreateProcess() API or any other way?
Thanks,
Expression:(L"Buffer is too small" &&0) error from strcpy_s() function
That error occur from
#include <iostream> using namespace std; class String { private: char* s; int size; public: String(char*); // constructor ~String(); // destructor }; String::String(char* c) { size = strlen(c); s = new char[size + 1]; strcpy_s(s, size, c); } String::~String() { delete[]s; } int main() { char array[] = "Hello world"; String *s = new String(array); delete[] array; return 0; }
Can anybody make it work?
My VC++, MFC developed application runs slower in Windows 10 compared to Windows 7
Issue: Application runs slower in Windows 10 compared to Windows 7. Can any one tell me what can be the reason for this?
How to drop down in windows combo dialog box with key not mouse
Example in RC kind of:
//...
BEGINRTEXT "&Name:",IDNAME_STATIC,1,14,13,8
COMBOBOX IDNAME,15,13,286,150,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_TABSTOP
RTEXT //...
//..
This drop down of string list will work only if a user do it with mouse click.
How to set up event alert for such to work with a keyboard press instead like up/down key ? Thanks.
WMP Mute when UiMode is None
I have a problem when trying to mute sound from my Playlist when in UiMode "none".
The code
CWMPPlaylistCollection playlistCollection = m_player.GetPlaylistCollection(); CWMPPlaylist playList = playlistCollection.newPlaylist(_T("MyList")); playList.appendItem(m_player.newMedia(_T("V:\\Videos\\1.mp4"))); playList.appendItem(m_player.newMedia(_T("V:\\Videos\\2.mp4"))); playList.appendItem(m_player.newMedia(_T("V:\\Videos\\3.mp4"))); m_player.SetUiMode(_T("none")); m_player.SetWindowlessVideo(TRUE); m_player.SetStretchToFit(TRUE); m_player.SetEnableContextMenu(FALSE); BOOL bIsMute = m_player.GetSettings().GetIsAvailable(_T("Mute")); if (bIsMute) m_player.GetSettings().SetMute(TRUE); m_player.GetControls().play();
works well for the first video, but the sound is turned on when the second video automatically starts?
I have noticed, that if I select UiMode "full" or "mini" it works, then I can also see the mute button?
Any ideas what is wrong?
-cpede
PipeClient compilation problem
I need a PipeClient-Server pair for my C++ application. To say it is mine is an overstretch, the codes are from the GitHub.This is the Client. While attempting to compile it I get a note that warnings will be treated as errors. I went into the Project Properties and turned it off, besides I turned ALL the warnings off, nonetheless I get two errors after warnings WERE treated as errors. I have VS2017 Community Edition.
In this code slice (CPipeCLient.cpp, line 47 :
void CPipeClient::SetData(std::wstring& sData) { memset(&m_buffer[0], 0, AU_DATA_BUF); //memcpy(&m_buffer[0], sData.c_str(), __min(AU_DATA_BUF, sData.size())); wcsncpy(&m_buffer[0], sData.c_str(), __min(AU_DATA_BUF, sData.size())); // <== error }
This ia the error message:
Severity Code Description Project File Line Suppression State Warning C4996 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. MFCaptureD3D c:\cplusplus_projects\mfcaptured3d\mfcaptured3d\cpipeclient.cpp 47
But when I try to use wcsncpy_s I get another error. This time the Intellisense says that there is no such overload.
How to handle it?
Thanks, - MyCatAlex
Debuging in c++
Hi;
When I debug my c++ application, it immediately closes.
What should I do ?
Can I have some body's E-mail address ? (Because I am amateur)Ignorant as to how to start a pipe server-client pair.
I am trying to mutilate a Microsoft/GitHub code and adjust it to my particular needs in a C++ application. As a part of my "game" I need to activate a PipeServer. I chose
Named Pipe Server Using Overlapped I/O. I envision my task as creating a monoplex client-server combination with a possibility of using 2-3 clients in the future with one server. It should be a byte system, not the message one. so I created a class NewMultiClientPipeServer
where I copied the server code as presented at the link I posted. In the same cpp file I wrote another class:
class DoWork { public: void DoWorkW (void) { int bb; DoWork(); // constructor NewMultiClientPipeServer * newServ = new NewMultiClientPipeServer(); bb = newServ->_tmain(); std::cout << bb; } } NewWork;
My intention is to activate this Server by calling _tmain from winmain.cpp. Here is the place I think will be appropriate:
INT WINAPI wWinMain(HINSTANCE,HINSTANCE,LPWSTR,INT) { if (!GetConsole()) MessageBox(NULL, TEXT("Could not obtain console"), TEXT("GetConsole() failed"), MB_OK); int x = 42; // variable for printf printf("Value of x is %d\n", x); // CALLING SEQUENCE HERE?? HWND hwnd = 0;
Nothing I tried so far worked for me. I need help.
Thanks, - MyCatAlex
Writing a huge file from memory to network share C++
When I try to write a huge file (40 GB) from memory to a network share I can only achieve a transfer rate of 350 MB/s. But if I copy a file from the system to the same network share Windows copies with a transfer rate of more than 1GB/s. (10Gbit network)
I tried WriteFile(), WriteFileEx(), fwrite(), _write() always the same result. I tried different block sizes for the write commands no difference.
What is the difference in the Windows copy command?
It should be possible to write a file from memory to a network share as fast as the Windows copy command does.
best regards!
Static variable question?
hello, i want to ask if i do this right?
I think when declaring static in .h file
Then in .cpp I declare include .h, it will work as in one file.
however it does not seem to work! where i was wrong?
when i debug: The variable is not initialized
however in another similar project, it works. It seems to be possible due to the compiler structure (is this possible?)
Assigning multiple functions to the function pointer
In C#, we can assign multiple methods to the delegate using '+' operator.
In C++, is it possible to assign multiple functions to the function pointer?
If so, how to do it?
TextAnalysis interface
I am trying to invoke the SetNumberSubstitution() API of IDWriteTextAnalysisSink interface for a particular locale. Below is the code
HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&fact)); if (SUCCEEDED(hr)) { // strLocale conatins the locale hr = fact->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_CONTEXTUAL, strLocale.c_str(), TRUE, &sub); if (SUCCEEDED(hr)) { IDWriteTextAnalysisSink* sink; // Fails here hr = fact->QueryInterface(__uuidof(IDWriteTextAnalysisSink), reinterpret_cast<PVOID*>(&sink)); if (SUCCEEDED(hr)) { CString m_strValue; //Contains the value on which to set the substituion hr = sink->SetNumberSubstitution(0, m_strValue.GetLength(), sub); if (SUCCEEDED(hr)) { } } }
But the QueryInterface() call to get IDWriteTextAnalysisSink fails with error E_NOINTERFACE. Could someone please what could be wrong here?
How to autoschedule a thread and then stop it from main
in c++ main i want to send start a thread at the start of the program
this thread is supposed to call a function again and again until the end of the program s reached which means when every other thing is done in the main below this thread then
this thread should be stopped only.(not before that)
i need this thread to call a function recursively because i need to do something inside this function after specific time lets say after every 2 minutes i want this function
to execute itself mean while other functions in main are being completed sequentially.
After every function completes sequentially i want the thread to stop and i can't get any logic to do that below is my code i am unable to stop the thread with std::terminate()
i think think the problem is because of infinite loop in which function is calling itself recursively
i cannot think of any logic to do that
#include<chrono>
#include<thread>
#include<functional>
//#include<unistd.h>
#include<Windows.h>
using namespace std;
void do_something()
{
cout << "\ni am running after 1 minute in thread" << endl;
int sleep_time = 1000;
while (true)
{
Sleep(sleep_time);
do_something();
}
}
void simpleFunc()
{
cout << "\nsimple function to check";
}
int main()
{
cout << "\nIn main";
//thread t1(timer_start(do_something()), 1);
//while (true);
thread th1(do_something);
simpleFunc();
cout << "\nafter the thread in main";
Sleep(6000);
cout << "\nafter Sleep in main";
//th1.detach();
//th1.detach();
//th1.join();
std::terminate();
return 0;
//std::terminate();
//system("pause");
//return 0;
}
Linker error on dll project in VS2019
Hi,
I have a dll application which I try to build, then I get linker error in VS2019 community:
LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) .\MSVCRTD.lib(exe_main.obj) 1
I changed the configuration type to .dll after creating project as empty C++ console application.
Regards,
Meelawn
MFC Cdialog how to set text for listbox?
But with listbox, which method should I use to set text?
In addition, a little silly I would like to ask more about Clistbox is the type of MFC dialog box, how is it different from listbox control?
thanks a lot!
Edit: I added a variable (private) and a new function setText to the class, currently I am having a problem with DoDataExchange that doesn't seem to automatically activate.
Can someone tell me the reason?