?
Solved

can i do C++ windows application programming in VC++ 2008

Posted on 2009-02-11
27
Medium Priority
?
955 Views
Last Modified: 2012-05-06
I am trying to devlelop an win32 application which captures my Image(continuous) using webcam and shows on my screen using C++.

So, do you suggest me to Use C++ in VC++2008 or directly do it in VC++2008?

if i use former case, will there be any compatibility issues?
0
Comment
Question by:kishan66
  • 14
  • 8
  • 2
  • +2
27 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 23613299
Hi kishan66,

please clearify what you mean - I don't understand the difference between 'Use C++ in VC++2008' and 'directly do it in VC++2008' ...

ZOPPO
0
 

Author Comment

by:kishan66
ID: 23613447
i am new to this C++ world.
i have VC++2008 in my system. and as i menstioned above i have make that application.(using webcam)

So if i search online i could able to find some examples in c++ and im not sure i can use those examples directly in VC++ (with out any comaptability issues).

0
 
LVL 31

Expert Comment

by:Zoppo
ID: 23613564
Well, any code you have which doesn't use any OS-specific (except Windows) or IDE-specific (except VS 2008) or compiler specific (except MS Compiler) functions, headers, libraries or keywords should be usable without problems.

Even for the things I mentioned as 'except' can be incompatible with the code you gonna write, i.e. if you don't use UNICODE but the foreign code you want to use or if you don't build for 64-bit support but the foreign code is designed especially for 64-bit support.

Anyway, a lot of very useful code which can be found in the Internet is either platform independant or is already VS 2008 conform or can be adopted to VS 2008 without too much trouble.

As long as you want to write an application for Win32 and it seems you already have a VS 2008 I would suggest to use it. Some more specific decisions may be whether to use i.e. Managed C++ (for use with .NET) or MFC or ATL or some other VS 2008 specific stuff. So, i.e. if you don't want to use MFC you for sure can't use any code which uses MFC directly ...

Hope that helps,

ZOPPO
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:pepr
ID: 23613637
The MS Visual Studio 2008 contains the Visual C++ version 9. It implements the C++ standard very well. If you do not have any special objections, you should use the IDE (the editor from Visual Studio).

If you never developed an application for Windows, you may find some problems with the basics. Anyway, when you get some C++ sources for Windows, it is likely that you will be able to compile it using VC++ 9.

Do not forget to install the Visual Studio 2008 service pack 1.
0
 

Author Comment

by:kishan66
ID: 23613647
Thanks for the suggestion.
let me start working on it and will get back to you if i have any doubts.

Thank you once again.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 23613806
>>>> i could able to find some examples in c++ and im not sure i can use those examples directly in VC++

You rarely will find VC9 samples on the net. Most samples are VC6 (released 1998) where you'll get some compatibility issues, e. g. if you used a for loop like

   for (int i = 0; i < 10; ++i)

the 'i' was only valid for the for loop in VC9 while it was valid beyond for loop in VC6. Then, the STL (Standard Template Library) changed pretty much from VC6 to VC8 what might give some tricky issues most of them when compiling (thank heavens).

If you got samples from non-MS compilers you have bad cards if they use a own windows library. If the author of the code doesn't provide a VC project file with the sample you most probably have lost. Nevertheless you could use the code to learn how to implement but rarely have a chance to get it built (with reasonable efforts).

Samples from VC7 (VS2003) or VC8 (VS2005) should have less to no compatibility issues if they were 'unmanaged' (normal) C++. When using managed C++ (what actually is a different language with some similarities in syntax) the differences are bigger.
0
 

Author Comment

by:kishan66
ID: 23614979
How should i load list of the Web cam(s) available in a system into ComboBox suing VC++
0
 

Author Comment

by:kishan66
ID: 23615772
Is there a way we can do that. or its not possible?
0
 
LVL 86

Expert Comment

by:jkr
ID: 23616091
You can get a list of these by enumerating the capture drivers (which stand for their respective cameras), e.g.
#include <vfw.h>
#prahma comment(lib,"vfw32.lib")
 
#define	MAXCAPDRIVERS			10	// maximum drivers list size
 
    int j;
    char szName[80];
    char szVer[80];
 
    for (j =0; j < MAXCAPDRIVERS; j++) 
        if (capGetDriverDescription (j,
                szName, sizeof (szName),
                szVer,  sizeof (szVer))) 
	{
           SendMessage(hMyComboBox,CB_ADDSTRING,0,szName);
        }

Open in new window

0
 

Author Comment

by:kishan66
ID: 23627964
cannot convert parameter 5 from 'TCHAR [2048]' to 'LPSTR'

WideCharToMultiByte(CP_ACP,0,var.bstrVal, -1, str, 2048, NULL, NULL);

im getting while building video application through webcam using DirectShow
0
 
LVL 86

Expert Comment

by:jkr
ID: 23628000
Can you show more of your code?
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 1500 total points
ID: 23628174
>>>> cannot convert parameter 5 from 'TCHAR [2048]' to 'LPSTR'

LPSTR means char*. If TCHAR[]  couldn't be turned to char* it means that the TCHAR is a WCHAR (== wchar_t) what means you have a settings that your TCHAR is wide char or UNICODE in MS speech.  Parameter 5 is str (if the error refers to t´he statement you posted. Then, you should turn the str from TCHAR[] to char[] cause the WideCharToMultiByte expects a char* as 5th parameter and not a wchar_t* .


0
 

Author Comment

by:kishan66
ID: 23633135
Hi itsmeandnobodyelse,

Thanks for the prompt reply.
but things you mentioned are not clear.....

i am using Vs 2008. I even tried to change the Project Properties to "Character set = Multi byte Char Set" but no use.

--------------------------------------------------------------------------------------
Error "cannot convert parameter 5 from 'TCHAR [2048]' to 'LPSTR' ".
--------------------------------------------------------------------------------------


#include <atlbase.h>
#include <dshow.h>
#include <d3d9.h>
#include <vmr9.h>
....
....
...
 
int  CVMR_Capture::EnumDevices(HWND hList)
{
	if (!hList)
		return  -1;
 
	
	int id = 0;
	
    // enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;
//    ICreateDevEnum *pCreateDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
			  IID_ICreateDevEnum, (void**)&pCreateDevEnum);
    if (hr != NOERROR)
	{
 
		return -1;
	}
 
 
 
    CComPtr<IEnumMoniker> pEm;
    hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
								&pEm, 0);
    if (hr != NOERROR) 
	{
 
		return -1 ;
    }
 
    pEm->Reset();
    ULONG cFetched;
    IMoniker *pM;
    while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK)
    {
		IPropertyBag *pBag;
		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
		if(SUCCEEDED(hr)) 
		{
			VARIANT var;
			var.vt = VT_BSTR;
			hr = pBag->Read(L"FriendlyName", &var, NULL);
			if (hr == NOERROR) 
			{
				TCHAR str[2048];		
				
 
				id++;
				WideCharToMultiByte(CP_ACP,0,var.bstrVal, -1, str, 2048, NULL, NULL);
				
				
				(long)SendMessage(hList, CB_ADDSTRING, 0,(LPARAM)str);
 
				SysFreeString(var.bstrVal);
			}
			pBag->Release();
		}
		pM->Release();
    }
	return id;
}

Open in new window

0
 

Author Comment

by:kishan66
ID: 23633244
Hi ,
 in the code when i tried to change TCHAR str[2048] to char str[2048](line 53) my errors have increased.

these are the errors ----


1>VMR_Capture.obj : error LNK2001: unresolved external symbol _IID_IMediaEventEx
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _IID_IMediaControl
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _CLSID_FilterGraph
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _IID_IGraphBuilder
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _IID_IVMRWindowlessControl
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _IID_IVMRFilterConfig
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _CLSID_VideoMixingRenderer
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _IID_IBaseFilter
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _CLSID_VideoInputDeviceCategory
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _CLSID_SystemDeviceEnum
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _IID_ICreateDevEnum
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _IID_IAMStreamConfig
1>VMR_Capture.obj : error LNK2001: unresolved external symbol _FORMAT_VideoInfo
1>C:\Documents and Settings\Ratan\My Documents\Visual Studio 2008\Projects\Dialog\Debug\Dialog.exe : fatal error LNK1120: 13 unresolved externals

0
 
LVL 86

Expert Comment

by:jkr
ID: 23633336
To get rid of these, be sure to add

#include <initguid.h>

tp the top of your main source file and link with 'dxguid.lib', e.g.

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

(or add that lib to your project)
0
 

Author Comment

by:kishan66
ID: 23633644
changes made::::
- changed TCHAR str[] to char str[];
-i have added the   #include <initguid.h> to the source file
-and  linked "dxguid.lib" in the additional dependencies and given its location in the additional Library Directories of the Project Properties.

but still the same errors
0
 
LVL 86

Expert Comment

by:jkr
ID: 23633841
Sorry, forgot one detail, add #define INITGUID before the #include directive, e.g.
#define INITGUID
#include <initguid.h>

Open in new window

0
 

Author Comment

by:kishan66
ID: 23633933
No use. same errors

is that trying to passing a UNICODE string to a function expecting an ANSI string.
i mean does LPSTR expects an ANSI string.

can you plz explain me the cause of the error too.
0
 

Author Comment

by:kishan66
ID: 23634448
whtzup guys!!!!!!!!!!!!

Is there a way we can get rid of this error.

please let em know ..im just hanging in here
0
 

Author Comment

by:kishan66
ID: 23634669
Solved it.
I could able to get it from some  other site.

Though we include <dshow.h> in the header file we have to explicitly tell the compiler about the IID's by specifying the .lib file

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

though no errors...Devices are not loaded into my combobox. i mean some weird charecters are loaded .

but i webcam i able to capture my image live.

any info regarding this.
0
 
LVL 86

Expert Comment

by:jkr
ID: 23634827
In this case (regarding the "weird characters", I assume mixing charsets incorrectly) try
                        VARIANT var;
                        var.vt = VT_BSTR;
                        hr = pBag->Read(L"FriendlyName", &var, NULL);
                        if (hr == NOERROR) 
                        {
                                
                                id++;
                               
                                (long)SendMessage(hList, CB_ADDSTRING, 0,(LPARAM)var.bstrVal);
 
                                SysFreeString(var.bstrVal);
                        }
                        pBag->Release();

Open in new window

0
 

Author Comment

by:kishan66
ID: 23635043
why do we have to add "L" before a string for LPCWSTR (ex- L"Friendly name")
0
 
LVL 86

Expert Comment

by:jkr
ID: 23635137
That is because when UNICODE string literals are required, they are prefixed by that 'L' to indicate that they are UNICODE and not ASCII.
0
 

Author Closing Comment

by:kishan66
ID: 31545637
Thanks for the suggestion. it solved part of the problem...
fyi, along with changing TCHAR to char  also chage the Charecter set to MultiByte and also add #pragma comment(lib,"Strmiids.lib")  to the header file.
0
 
LVL 86

Expert Comment

by:jkr
ID: 23636118
????

You had serveral questions here, and several people contributed.
0
 

Author Comment

by:kishan66
ID: 23636756
Hi jkr,

thanks for helping .!!
but i was not aware that i only can accept one solution.

0
 
LVL 86

Expert Comment

by:jkr
ID: 23637732
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question