Jump to content
  • Advertisement
Sign in to follow this  
alex9025

code wont compile

This topic is 4003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys I'm trying to compile this code, but it keeps giving my linker errors... tried DevC++ and VS2008b btw Borland C++ builder compiles it just fine. the error is
error C2664: 'mciSendStringW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
#include "stdafx.h"
#include "windows.h"
#include "mmsystem.h"
#include "iostream"

using namespace std;
char choice;
bool quit;
int main()
{
	while (!quit)
	{
		cout << "Please select what you want to do" << endl;
		cout << "[O]pen CD/DVD rom" << endl;
		cout << "[C]lose CD/DVD rom" << endl;
		cout << "[Q]uit" << endl;
		cin  >> choice;
		switch (choice)
		{
			case 'O': case 'o':
				mciSendString("open CDAudio", NULL, 0, NULL);
				mciSendString("set CDAudio door open", NULL, 0, NULL);
				cout << "Its open" << endl;
				break;
			case 'C': case 'c':
				mciSendString("close CDAudio", NULL, 0, NULL);
				mciSendString("set CDAudio door closed", NULL, 0, NULL);
				cout << "Its closed" << endl;
				break;
			case 'Q': case 'q':
				quit = 1;
				break;
			default:
				cout << "You did not enter anything" << endl;
				break;
		}
	}
}

Share this post


Link to post
Share on other sites
Advertisement
In MSVC 2008, projects default to using Unicode versions of the Windows API functions. You can change that by going to Project Properties/Character Set and change it to Use Multi-Byte Character Set.

Share this post


Link to post
Share on other sites
after I did that it gives me
Linking...
open.obj : error LNK2019: unresolved external symbol __imp__mciSendStringA@16 referenced in function _main

Share this post


Link to post
Share on other sites
Your includes at the top...


#include "stdafx.h"
#include "windows.h"
#include "mmsystem.h"
#include "iostream"



Shouldn't this be...


#include "stdafx.h"
#include <windows.h>
#include "mmsystem.h"
#include <iostream>



Since windows.h and iostream are in the compiler include path? I'm not sure what mmsystem.h is or if it's in the path as well, or if it's just part of the project.

If it's not either of those, it looks like you're using a library that you're not linking into the build. That is, including the appropriate .H file, but not telling the linker to add in the .lib.

Share this post


Link to post
Share on other sites
mmsystem.h is indeed a system file, although I was under the impression it was automatically included with windows.h. Either way, this wouldn't cause a linker error, just an include compile-time error.

alex9025, the reason you are getting that linker error is that you aren't linking to the library that provides the mciSendString function, which is found in winmm.lib. To include this library, either add it to the list in the options page, or add the following line to one of your source files:

#pragma comment(lib, "winmm.lib")

Share this post


Link to post
Share on other sites
ugh guys I need more help,
after I changed the configuration from debug to release it gives me that same error again
open.cpp(21) : error C2664: 'mciSendStringW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

why is it doing that, only on release and if i change it to debug it compiles just fine

Share this post


Link to post
Share on other sites
You probably need to change the Character Set settings again, they're usually determined per configuration which is why the debug build builds but the release build fails.

Share this post


Link to post
Share on other sites
yeah that fixed it thanks.
but now when I send that program to another pc
(win server 2003)
it gives me an error when I try to run the file
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

Share this post


Link to post
Share on other sites
The google keywords for this very cryptic message is Side by Side (SxS) issues and Visual C++ redistributable.

Your program dynamically links to a number of libraries, including the C and C++ runtime. Since your dynamically linking, the dlls need to be present as well when running the program.

Two ways to make them appear on another computer. Run the redistributable. VS 2008 uses VC 9 redistributable. Or go to the Visual Studio Directory / vc / redist (I think) and copy the CRT and any other needed dlls as well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!