I know this is a very stupid question and I'm very new to C++.
I'm developing Starcraft AI, it is DLL file. I'm trying to use XML to gather some data to the bot, however whenever I build the DLL with /clr option. The bot doesn't load properly. So, my question is what is CLR and is there a way to read/write XML without using /clr build option.
Thanks so much.
The /clr compiler option enables the
use of Managed Extensions for C++ and
creates an output file that will
require the .NET Framework common
language runtime at run time.
(from MSDN)
Starcraft is probably not developed under CLR (.NET Framework runtime).
I've used the free tinyxml library from C++ code - it was quick to get running and reasonably efficient. Well, about as efficient as it's possible for XML to be, anyway.
Starcraft probably won't run .NET binaries. You would have to either write your own XML parser, which probably isn't for you seeing as you are new to C++, or find a C++ library that can do it for you.
Example of one:
http://sourceforge.net/projects/tinyxml/
Related
I'm trying to write my first game in c++, and I want it to dynamically load everything from files. This includes the enemies, and I was wondering if there was a way to dynamically include their code at runtime, instead of linking the on compile, so that the levels are easily interchangeable. Lua might be an option but I have no clue where to start, and dll seems to be Windows-only (and I wouldn't know where to start there anyway). Can anyone help with this?
tl;dr I want to link in code to my c++ game at runtime.
For the Lua approach you first need to choose the version first. Right now there is the major version 5.1 and 5.2. My previous work was using 5.1 and for my new project I decided to update to 5.2, however I found that my favorite script wrapping tool (SWIG) does not work with 5.2. Just something to decide at the beginning, because you do not want to get a version working and then have to change it.
Lua comes with makefile build environment. My first experience of trying to build on Windows was a bit of a nightmare, did not appear to just run out-of-the-box, so I opted to create my own Visual Studio project at the time, and just include all the .C files in the project. There are two files which need to selectively included/excluded depending on how you intend to compile: lua.c and luac.c. If you are planning to embed Lua in your app, then exclude both of these files; they both contain a main() function and are designed to build console apps. Include all the rest of the C files in your project.
You should be able to compile easy from this point.
When you include the headers of Lua, keep in mind that the functions are C functions so if you are including them from C++ you need to wrap the file inclusion inside of: extern "C" {} - example: C++ Lua 5.1 Issue
Wrapping your interfaces in another topic and there are lots of resources available. My favorite is SWIG but there are lots of options, including hand coding the conversion of your C/C++ -> LUA -> C/C++ code. Would recommend just focusing on getting the first part working first, get the interpreter embedded so that you can run a "hello, world!" script from Lua inside your app.
So going by your requirement of crossplatform use and dynamic linking, what you're probably looking for is an environment like QT which has QLibrary: https://stackoverflow.com/a/9675063/453673
But https://softwareengineering.stackexchange.com/questions/88685/why-arent-more-desktop-apps-written-with-qt
MingW is the open-source equivalent for Visual C++, so it can help you writing code for Windows (though if I had a choice, I'd directly use Visual C++). The way dll's are loaded in Windows is somewhat similar to the way they're loaded in Linux, so you'll be able to write code with #ifdef's to do conditional compilation. I've written one such program a couple of years back.
To load a shared library(always with .so as suffix) under Linux, you could use dlopen(), dlsym() and dlclose()
Is there any framework written in C/C++/C++11 for writing code completion tools?
Or maybe are there some libraries that allow code completion for Java or C++ (also written in C++?).
I'm writing my custom IDE in C++ for Java (and not only Java) development and I want to add code completion support to it the best possible way, without reinventing the weel ;)
clang_complete is a plugin for vim for accurately completing C, C++, Objective-C and Objective-C++ code: https://github.com/Rip-Rip/clang_complete/
It uses clang - an open source C++ compiler written in C++ for doing the job. I guess you may find it useful.
Our VB6 program currently calls code in a C++ dll. This dll does not need to be registered, it only needs a .def file specifiying the properties and methods. Vb6 late binds to it. The dll is written in VS2005 without a dependency on the Net framework.
As we are migrating our application to Net4 and also want to enhance the C++ dll with new functionality, I was wondering how to migrate the existing C++ code to VC++. I suppose thereafter the dll will just happily integrate in our solution which already contains C# and VB.Net libraries too.
Is there some tutorial/documentation about the do's and don'ts of this plan?
EDIT:
I think I have some basic misunderstanding about VC++, thinking that it can be ported to 100% managed code while keeping the C++ syntax. The replies I get seem to indicatie that VC++ will always produce native, unmanaged code?
From a pure C++ point of view, you should be able to convert the VS2005 solution and project to VS2010 automatically. If I recall when you load the solution or project into VS2010 it will automatically convert it for you.
If you open the VS2005 project file in VS2010, VS2010 will automatically convert the old project to the new project format and the auto-conversion will do it's very best job to get everything correct. This usually works, but not always. So the moral of the story here is, double-check all of the new project's compiler/link settings, to be on the safe side.
Also with VS2010, you have some better interop possibilities between managed and native code: P/Invoke and C++/CLI. P/Invoke is simpler, but you will find that stuff may compile but fail at runtime. C++/CLI is way more flexible, a bit more work, but makes it much easier to debug the interop, when it becomes necessary.
I'm a total noob when it comes to linking and building with Visual Studio. I would like to integrate Lua into my C++ console application.
Can someone give a step by step on how to do this from getting the Lua dependencies from lua.org, to actually running a "Hello World from Lua" in VS, and all the steps in between.
Finding something like this online has been very difficult since most require prerequisite knowledge of building Lua and such.
Thanks :)
Start with the Lua for Windows package. It will get you a self-contained batteries included Lua installation. Lua for Windows is not an official distribution, but it is well respected by the Lua user community. You can use its lua.exe to gain experience with the language in a Windows environment, and its rich collection of tested extension modules is also available for use.
If you add its include and lib folders to your VS project configuration, you should be able to compile and link against Lua in short order.
One possible complication is that the LfW distribution is built against VC8's C runtime library. If that becomes a problem, then you can either compile Lua yourself as part of your Solution, or get a known good DLL that matches your specific version of Visual Studio from the Lua Binaries project.
Do remember that if you are using one of the distributed DLLs, it will have been compiled as C, and not C++. That means that you must wrap any references to the Lua include files in extern "C" {...} or you will have problems with linkage.
It really helps to have some experience with VS project configuration and building. In particular, experience with mixing C and C++ in a VS project is very helpful.
I heartily recommend following the advice already given about learning C and C++ and mixing the two together. Once you have that under your belt, you may want to check out LuaBind or LuaPlus for connecting C++ and Lua. You can do it manually (and you probably should, at first, to understand what's going on under the hood), but it's more efficient and cleaner, code-wise, to use one of those binding libraries. For debugging purposes, Decoda is a good choice; it can attach to processes started in VS which contain Lua code you want to check.
I'm going to create a utility with GUI that will run on Windows operating systems.
It should require minimum (or zero!) amount of additional libraries, files or DLLs to run because it will be executed from an installer. Because of this, i don't want to use .NET for it will require user to install .NET Framework. I know today, most of Windows installed system come with .NET Framework but in my case i cannot be sure.
The utility will...
send some data to a web site and
parse the returning data,
collect some hardware info, like MAC address,
CPU type and make, hard-disk serial
number
I suppose native Win32 API could be used for all of those above, but instead of hassling with Win32, i'd prefer using a more developer friendly API, or SDK.
Thanks in advance.
Win32 API is the only way, and of course there are standard API - for sending data over the internet, you could use WinInet.lib/dll, to obtain information about the MAC, you could use the GetAdaptersInfo by using Iphlpapi.lib/dll,(here's a link on how to use it) for the Hard disk serial number you could use GetVolumeInformation by using kernel32.lib/dll. For the CPU Id, you might look into GetSystemInfomation
Edit: There's a C++ code, but you can easily derive a wrapper from this site Unfortunately, with WinAPI is not easy, no such thing as RAD with WinAPI but what you gain out of it is lightweight code instead of relying on SDK's, frameworks and dragging buggy dll's around with your application.
Hope this helps,
Best regards,
Tom.
You can statically link most C++ GUI libraries - even MFC. Personally, I recommend WTL, wihich is very light and header-only.
If what you want is minimum dependency with external files or DLLs you could statically compile all the required DLLs with the tool exe. Then you could use something like Visual C++ to develop such tool.
WTL is perfect for this sort of application and I am surprised more people aren't recommending it. You can also statically link with the CRT and hey presto - no dependencies and a very small EXE.
Delphi (now by Embarcadero) would do the job, creating a .exe file with no dependencies, and it is much easier to work with than the raw Win32 API.
If you don't like Object Pascal, you could try C++ Builder instead.
For the GUI you can either build your application with MFC (statically linked) or use a HTML based dialog that you can interact with using COM. (It is even possible to interact with javascript present in the page displayed by the dialog).
For the specific requirement that you do have, I feel Win32 API is the only way out.
Use MFC and statically link to it. No runtime dependancies need to be installed.