Visual Studio 2013 Express - How do I add resources? - c++

I'm currently linking to the >dynamic< libs in SFML but I have no idea how to add resources in Visual Studio 2013 Express C++. I've quite recently started out with C++, coming from C# where adding resources is as simple as drag-n-drop.
I know there's something with .rc files and headers, but I didn't find any guide on it. What I need to do is add the dll's so I don't have to manually paste them with the .exe and I also need to add .png's. Right now I'm loading them from a folder next to the executable, I don't wanna do that.
How do I do this?

You can just add an [.rc] file to the project.
An [.rc] file is a purely textual resource script that you can edit as text, or you can use various 3rd party resource editors (you don't need that for adding image resources, just check out the RC syntax).
Visual Studio Express lacks resource editors, but does support automatic recognition of, compilation of and linking of resources.
Example
Here's an example [.rc] file, just a single line, using a free icon that I just downloaded from the net:
100 ICON "resources\\Bad-Blood-Yolks-Grin.ico"
Corresponding C++ source code, presenting the icon in a message box:
#undef UNICODE
#define UNICODE
#include <windows.h>
auto main() -> int
{
MSGBOXPARAMS params = {sizeof( params )};
params.hInstance = GetModuleHandle( nullptr );
params.lpszText = L"Click OK to dismiss this box.";
params.lpszCaption = L"Καλὴ τύχη!"; // "Good luck!" in Greek.
params.dwStyle = MB_USERICON;
params.lpszIcon = MAKEINTRESOURCE( 100 );
MessageBoxIndirect( &params );
}
Result:
All done in Visual C++ Express for Desktop 2013, or whatever it calls itself. :-)
In order to synchronize identifiers between resource script and C or C++ code it's common to include a header. The resource compiler understands the most basic C preprocessor directives.
Oh, also, I added the [.rc] file as just a text file. Visual Studio Express reacts to the renaming, "rc" file extension, by popping up a warning box that it isn't supported. Just ignore the box, and to edit the file right-click and choose text editor.

Related

pplawait.h / experimental/resumable for co_await doesn't work

I have installed on windows 10.0 visual studio 2017 (version 15.2)
I have migrating from VS2013 to VS2017 for my project (that include cpprestsdk) and change .then() method with co_await. I have read something on the web but actually i can't compile my solution anymore.
Cannot open include file pplawait.h
ignoring unknown opion '/await'
Suggestions?
Using coroutines with Visual Studio 2017 and an MFC solution into which I am using C++/WinRT with its async type functions, I have the following.
See as well this question and my answer which contains several examples of using coroutines with concurrency, std:async and C++/WinRT: C++11 threads to update MFC application windows. SendMessage(), PostMessage() required?
First of all settings in the solution Properties.
Configuration Properties -> General -> Platform Toolset Visual Studio 2017 (v141)
C/C++ -> All Options -> Additional Options -> /await
C/C++ -> All Options -> C++ Language Standard ISO C++17 Standard (/stdc++17)
And the source code for the actual function that I am using (C++/WinRT async function with co_await):
#include <pplawait.h>
#pragma comment(lib, "windowsapp")
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.Web.Syndication.h"
// . . . other code
// sample function using co_await to retrieve an RSS feed which may take
// a while so we want to start it and then continue when the results are
// received. we are using one of the async functions of C++/WinRT to retrieve
// the RSS feed text. We require a pointer to a CMainFrame object which has
// the function we need to output the text lines to a displayed window.
winrt::Windows::Foundation::IAsyncAction myTaskMain(CMainFrame *p)
{
winrt::Windows::Foundation::Uri uri(L"http://kennykerr.ca/feed");
winrt::Windows::Web::Syndication::SyndicationClient client;
winrt::Windows::Web::Syndication::SyndicationFeed feed = co_await client.RetrieveFeedAsync(uri);
// send the text strings of the RSS feed list to an MFC output window for
// display to the user.
for (winrt::Windows::Web::Syndication::SyndicationItem item : feed.Items())
{
winrt::hstring title = item.Title().Text();
p->SendMessageToOutputWnd(WM_APP, COutputWnd::OutputBuild, (LPARAM)title.c_str()); // print a string to an output window in the output pane.
}
}

C++ Port in VS: new project crashes (same files & settings)

I am trying to move the code from a preliminary project to a new project (both made under Visual Studio 2012).
The original one has been made as a console application and I want the new to be a Windows application. I created an empty project and moved the files/set the library paths.
It is a simple OpenGL program with shaders.
EDIT:
It happens that even when I switch back to creating a Console application with the same .vcproj properties, I have a fatal error on Release and Debug.
You can find them below.
Why does my program crash? All the library paths are set just fine because it's the same settings used for a previous project with the same files that DID work (in a different solution).
Errors
Release crash location (outside a #ifdef _DEBUG in the dbghook.c
file)
int _debugger_hook_dummy;
__declspec(noinline)
void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
{
/* assign 0 to _debugger_hook_dummy so that the function is not folded in retail */
(_Reserved);
_debugger_hook_dummy = 0;
}
Debug crash location (fread.c) - a pop-up error window appears
(Debug assertion failed):
_VALIDATE_RETURN((stream != NULL), EINVAL, 0);
After cutting my source file in parts, I managed to debug this. The problem was not the port (sorry).
I had minor issues dealing with the location of the executable: Visual Studio puts them by default in SolutionDir/DebugorRelease while I was looking for them in ProjectDir/DebugorRelease.
But the main problem came from a change of function.
There is a side file I use to load textures, which is pretty old and uses fopen to open files.
Following the warnings I got, I changed all the fopen occurrences to fopen_s, with all necessary modifications. That's the precise line where the program crashed.
I put back the fopen version, checked the file locations, and it went back to executing (not in Visual Studio but through command line only, like the original project). That's for the Console Application.
To make it a Windows Application, the following line does the job, and this time, though command-line-only, it works for real.
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )

How to compile c++ file in visual studio?

I am new to Visual Studio and I don't know how to compile a .cpp file. I made just a single .cpp file (ctr + n => Visual C++ => C++ file) and I tried to compile it. But in place where normally there's a compile button (like with c#) there is strange 'Attach' button. I don't get what's going on, but I thought, Visual C++ might be some different version of normal C++. If so is that possible to compile normal C++ file in Visual Studio?
The problem is, Visual Studio don't really know, what to do with your .cpp file. Is it a program? Try the following:
File | New project
Visual C++ | Win32 | Win32 Project
Select a name and location for the project
Next
Choose Console application
Choose Empty project
Deselect Precompiled header
(optionally) Deselect SDL checks
Finish
Right-click on Source files and choose Add | New Item...
Choose C++ File
Choose name for this file
Write the following inside:
#include <stdio.h>
int main(int argc, char * argv[])
{
printf("Hello, world!\n");
return 0;
}
Press F5
You should, just as you did for C#, create a C++ project and add your source file to that. Then there will be all the build options you ever dreamed of.

How to implement Tesseract to run with project in Visual Studio 2010

I have a C++ project in Visual Studio 2010 and wish to use OCR. I came across many "tutorials" for Tesseract but sadly, all I got was a headache and wasted time.
In my project I have an image stored as a Mat. One solution to my problem is to save this Mat as an image (image.jpg for example) and then call Tesseract executable file like this:
system("tesseract.exe image.jpg out");
Which gets me an output out.txt and then I call
infile.open ("out.txt");
to read the output from Tesseract.
It is all good and works like a chair but it is not an optimal solution. In my project I am processing a video so save/call .exe/write/read at 10+ FPS is not what I am really looking for. I want to implement Tesseract to existing code so to be able to pass a Mat as an argument and immediately get a result as a String.
Do you know any good tutorial(pref. step-by-step) to implement Tesseract OCR with Visual Studio 2010? Or your own solution?
OK, I figured it out but it works for Release and Win32 configuration only (No debug or x64). There are many linking errors under Debug configuration.
So,
1. First of all, download prepared library folder(Tesseract + Leptonica) here:
Mirror 1(Google Drive)
Mirror 2(MediaFire)
2. Extract tesseract.zip to C:\
3. In Visual Studio, go under C/C++ > General > Additional Include Directories
Insert C:\tesseract\include
4. Under Linker > General > Additional Library Directories
Insert C:\tesseract\lib
5. Under Linker > Input > Additional Dependencies
Add:
liblept168.lib
libtesseract302.lib
Sample code should look like this:
#include <tesseract\baseapi.h>
#include <leptonica\allheaders.h>
#include <iostream>
using namespace std;
int main(void){
tesseract::TessBaseAPI api;
api.Init("", "eng", tesseract::OEM_DEFAULT);
api.SetPageSegMode(static_cast<tesseract::PageSegMode>(7));
api.SetOutputName("out");
cout<<"File name:";
char image[256];
cin>>image;
PIX *pixs = pixRead(image);
STRING text_out;
api.ProcessPages(image, NULL, 0, &text_out);
cout<<text_out.string();
system("pause");
}
For interaction with OpenCV and Mat type images look HERE
It has been a lot since the last reply but it may be help to others;
I think you must also add "liblept168.lib" and "liblept168d.lib" to Additional Dependencies
Add "liblept168.dll" and "liblept168d.dll" to the destination of your exe.
Add #include to your code.
(This answer must be a comment to Bruce's answer. Sorry for confusion. )
You need to use the library through the API.
Most probably:
start by downlaoding the libs ( https://code.google.com/p/tesseract-ocr/downloads/detail?name=tesseract-3.02.02-win32-lib-include-dirs.zip&can=2&q= ). They're compiled with Visual 2008 but it should be enough
Use the API directly (example, look at an open source project using it: https://code.google.com/p/qtesseract/source/browse/#svn%2Ftrunk%2Ftessdata ) and read the links from this answer : How can i use tesseract ocr(or any other free ocr) in small c++ project?

Having trouble embedding Lua for Windows install into C++ program

This is the first question I have found myself not being able to get to the bottom of using my normal googling/stack overflowing/youtubing routine.
I am trying to compile a minimal Lua program inside of a C++ environment just to ensure my environment is ready to development. The Lua language will be later used for User Interface programming for my C++ game.
First some basic information on my environment:
Windows 7 64-bit
Visual studio 2010
Lua for Windows 5.1 (latest build I could download from google code)
Here is the code I am trying to compile:
// UserInt.cpp : Defines the entry point for the console application.
//
#pragma comment(lib,"lua5.1.dll")
#include "stdafx.h"
#ifndef __LUA_INC_H__
#define __LUA_INC_H__
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
int _tmain(int argc, _TCHAR* argv[])
{
lua_State * ls = luaL_newstate();
return 0;
}
#endif // __LUA_INC_H__
Here is the Error I am getting:
1>UserInt.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _wmain
1>c:\users\deank\documents\visual studio 2010\Projects\UserInt\Debug\UserInt.exe : fatal error LNK1120: 1 unresolved externals
Things I have tried:
I have read about lua_open()(and several other functions) no longer being used so I tried the newstate function instead. I get the same error. This was more of a sanity check than anything. I am using 5.1 and not 5.2 so I do not think this really matters.
I have also read this thread Cannot link a minimal Lua program but it does not seem to help me because I am not running the same environment as that OP. I am on a simple windows 7 and visual studio environment.
The top pragma comment line was something I saw in yet another thread. I get the same error with or without it.
I have gone into my visual studio C++ directories area and added the lua include to the includes and the lua lib to the libraries.
So it seems like my program is seeing the .h and seeing the symbol. But for some reason it is not getting the .cpp implementation for the functions. This is why I was hoping including that .dll directly would help fix the problem, but it hasn't.
So, I feel like I have exhausted all of my options solving this on my own. I hope someone is able to help me move forward here. Lua looks like an awesome language to script in and I would like to get my environment squared away for development.
I hope it is just some silly error on my part. I believe I have provided as much information as I can. If you need more specifics I will update with info if I can provide it.
Edit1
Tried the solution in this Can't build lua a project with lua in VS2010, library issue suspected
That did not work either.
You'll need to have the library (.LIB) file and add that to VS. Use Project > Properties and go to Linker > Input and add the full .lib filename to the "Additional Dependencies" line. Note that the .LIB is different from the .DLL.
Personally, I prefer adding the source code to my project, over referencing the dynamic link library. The following procedure will let you do as such.
Download the source code ( http://www.lua.org/ftp/ ), uncompress it.
In Visual Studio, choose File > New > Project and choose Visual C++, Win32, "Win32 Console Application".
In your project in Visual Studio, add all the source code, except luac.c. Also delete the main() function out of the file that VS created for you. This is usually given the name of the project you specified with the .cpp file extension. You could just remove this file all-together from the project.
Build and Run.
This is the Lua console