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

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?
kishan66Asked:
Who is Participating?
 
itsmeandnobodyelseCommented:
>>>> 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
 
ZoppoCommented:
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
 
kishan66Author Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
ZoppoCommented:
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
 
peprCommented:
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
 
kishan66Author Commented:
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
 
itsmeandnobodyelseCommented:
>>>> 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
 
kishan66Author Commented:
How should i load list of the Web cam(s) available in a system into ComboBox suing VC++
0
 
kishan66Author Commented:
Is there a way we can do that. or its not possible?
0
 
jkrCommented:
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
 
kishan66Author Commented:
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
 
jkrCommented:
Can you show more of your code?
0
 
kishan66Author Commented:
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
 
kishan66Author Commented:
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
 
jkrCommented:
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
 
kishan66Author Commented:
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
 
jkrCommented:
Sorry, forgot one detail, add #define INITGUID before the #include directive, e.g.
#define INITGUID
#include <initguid.h>

Open in new window

0
 
kishan66Author Commented:
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
 
kishan66Author Commented:
whtzup guys!!!!!!!!!!!!

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

please let em know ..im just hanging in here
0
 
kishan66Author Commented:
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
 
jkrCommented:
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
 
kishan66Author Commented:
why do we have to add "L" before a string for LPCWSTR (ex- L"Friendly name")
0
 
jkrCommented:
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
 
kishan66Author Commented:
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
 
jkrCommented:
????

You had serveral questions here, and several people contributed.
0
 
kishan66Author Commented:
Hi jkr,

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

0
 
jkrCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.