This is a discussion on Visual C++ Tips & Tricks within the C and C++ Programming forums, part of the Software Development category; About Microsoft Visual C++: An application development tool developed by Microsoft for C++ programmers. Visual C++ supports object-oriented programming ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| About Microsoft Visual C++: An application development tool developed by Microsoft for C++ programmers. Visual C++ supports object-oriented programming of 32-bit Windows applications with an integrated development environment (IDE), a C/C++ compiler, and a class library called the Microsoft Foundation Classes (MFC). The IDE includes an AppWizard, ClassWizard, and testing features to make programming easier. Visual C++ was introduced in 1993, and Release 4.0 became available in 1996. Iam a Visual C++ developer and i have gained vast experience by working with this tool right from its introduction. Now i would like to share all my knowledge and experience through this website and i will be giving lots of Visual C++ Tips. I hope this will be helpful for the Visual C++ developers around the world. I will be contributing to this thread on a regular basis so please check back this thread regularly. If you are a Visual C++ beginner, you can join this community and ask me any queries you have in Visual C++ and i will be happy to help you out. If you are an experienced Visual C++ developer i welcome you to join the list of experts in this community to help others and share your knowledge. Iam starting with a Visual C++ tip right now. When i tried to create a dll in c using visual c++ compiler i received the errors below. LNK2001: unresolved external symbol _main Debug/windll.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. Reason: The problem is in creating a executable file hence the compiler is looking for the main method.. Inorder to create a DLL file we have to some manipulation in the project properties. i.e open ur project properties window and select the link tab.Change the output file from exe to DLL and in the "Project Options" text box change the "subsytem console" to "dll" thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Booom : 08-22-2007 at 11:24 AM. |
|
#2
| |||
| |||
| Hi all, Below I have given the trick to create borderless window in Visual C++. Hope it will be very useful for your vc++ project. BORDERLESS WINDOW DWORD dwStyle = GetWindowLong((ProgEntry->m_Prog).m_hWnd, GWL_STYLE); SetWindowLong((ProgEntry->m_Prog).m_hWnd, GWL_STYLE, dwStyle ^ WS_BORDER); SetWindowLong((ProgEntry->m_Prog).m_hWnd, GWL_EXSTYLE, GetWindowLong((ProgEntry->m_Prog).m_hWnd, GWL_EXSTYLE)^WS_EX_CLIENTEDGE); simple code but very useful... ![]()
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Booom : 08-09-2007 at 04:37 AM. |
|
#3
| |||
| |||
| Hi All, Here is the tip for TCHAR conversion in Visual C++. I have given the sample conversion program source code. TCHAR convertionthanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Booom : 08-09-2007 at 04:37 AM. |
|
#4
| |||
| |||
| The following example demonstrates the use of CStringT::FormatV. Its very simple to write a program for formatting the variables in Visual C++. Below is a sample #include <string.h> #include <atlsimpstr.h> #include <atlstr.h> void WriteString(LPCSTR pstrFormat, ...) { CString str; // format and write the data you were given va_list args; va_start(args, pstrFormat); str.FormatV(pstrFormat, args); va_end(args); printf(str); return; } int main( ) { WriteString("%d error(s) found in %d line(s)", 10, 1351); } thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Booom : 08-09-2007 at 04:38 AM. |
|
#5
| |||
| |||
| Hi, I have given the technique to use array in Visual C++ below. Hope it is useful for you. Array Declaration // example of 2 dimensional array typedef CArrayEx CIntArray; CArrayEx<CIntArray, CIntArray &> a2D; CIntArray aInt; a2D.Add (aInt); // auto_ptr example. CArray<AUTO_PTR,auto_ptr<CValue> > a; CArray<AUTO_PTR,auto_ptr<CValue> > b; TRACE(_T("Create\n")); a.Add(auto_ptr<CValue>(new CValue(1))); a.Add(auto_ptr<CValue>(new CMyValue(2))); b.Add(auto_ptr<CValue>(new CValue(3))); b.Add(auto_ptr<CValue>(new CMyValue(4))); // TRACE(_T("Copy\n")); // a.Copy(b); TRACE(_T("Append\n")); a.Append(b); TRACE(_T("Remove all\n")); b.RemoveAll(); thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Booom : 08-09-2007 at 04:38 AM. |
|
#6
| |||
| |||
| Some useful techniques and ways of using WTL features like: • dialog box is resizable The VC++ 6.0 project that comes with this article is an ATL in-process COM server, housing Browser Helper (BHO) and IE Extension objects. When the IE browser downloads HTML page, BHO will pop up a dialog box with a treeview which will display Document Object Model (DOM) nodes and attributes of that HTML document. thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention |
|
#7
| |||
| |||
| How to get the URL from ActiveX Control This is a simple technique to determine the URL of the web page in which the ActiveX control is hosted. I had to develop ActiveX controls for web based applications. Some of these controls were manipulating the local resources. To disable malicious use of these control by others through scripting, I had to implement security check. I decided to implement a simple security scheme where I determine the url in which the control is hosted. If the url comes from our domain, I enabled its functionality. I used GetMoniker method of IOleClientSite Interface.The IMoniker interface has GetDisplayName() method, which returns a user-readable representation of the moniker. Sample Code HRESULT hrResult = S_FALSE; IOleClientSite *pClientSite = NULL; IMoniker* pMoniker = NULL; LPOLESTR sDisplayName; // If using ATL to develop, use the m_spClientSite data // member of CComControl class. // If using MFC, use the following code: // (member function of COleControl class // - don't forget to call release) // pClientSite = GetClientSite(); hrResult = m_spClientSite->GetMoniker(OLEGETMONIKER_TEMPFORUSER, OLEWHICHMK_CONTAINER, &pMoniker); if(SUCCEEDED(hrResult)) { hrResult = pMoniker->GetDisplayName(NULL, NULL, &sDisplayName); pMoniker->Release(); } //TODO : relevant processing with sDisplayName and //free sDisplayName using SysFreeString() thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention |
|
#8
| |||
| |||
| Common WinInet MFC Classes Here is MFC classes hierarchy. In MFC hierarchy you see CFtpConnection, CHttpConnection, and CGopherConnection classes are derived from CInternetConnection. WinInet MFC ClassesthanksCObjectCInternetSession ![]()
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Karpagarajan : 03-27-2007 at 03:33 PM. |
|
#9
| |||
| |||
| Here is the sample FTP program in Visual C++ CFtpConnection* m_pFtpConnection; m_pFtpConnection = m_pInetSession->GetFtpConnection(strServerName, szftpUserID, szftpPassword, nPort, FALSE); // Do connection to the FTP server if ( m_pFtpConnection->PutFile(lpExePath + "default.asp", "default.asp", FTP_TRANSFER_TYPE_BINARY, 1) == 1 ) AddLog("File : default.asp uploaded successfully."); else AddLog("Error in file :default.asp upload."); thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Booom : 08-09-2007 at 04:39 AM. |
|
#10
| |||
| |||
| Differences between release and debug builds I used the phrase 'debug build' quite a few times in the preceding paragraphs. It's important to understand that asserts are a debug helper. If you're building a debug version of your program the compiler includes all the code inside the ASSERT(...). If you're building a release version the ASSERT itself and all the code inside the parentheses disappears. The assumption is that you've tested your debug builds and caught all likely errors. If you're unlucky and missed an error and release a buggy version of your program the hope is that it'll limp along even though it failed a test that an assert would have caught. Sometimes optimism is a good thing! It might happen that you want, in a debug build, to assert that something is true and the something you're asserting is code that must be compiled into your program whether it's a debug build or a release build. That's where the VERIFY(...) macro comes to the rescue. VERIFY in a debug build includes the extra plumbing MFC provides to let you jump into the debugger in the event that the condition isn't satisfied. In a release build the extra plumbing is omitted from your program but the code inside the VERIFY(...) statement is still included in your executable. For example. VERIFY(MoveFile(szOriginalFilename, szNewFileName)); will cause a debug assert if, for whatever reason, the MoveFile() function fails in debug builds. Regardless of what kind of build the MoveFile() call will be included in your program. But in a release build the failure of the call is simply ignored. Contrast this with ASSERT(MoveFile(szOriginalFilename, szNewFileName)); In debug builds the MoveFile() will be compiled and executed. In release builds the line completely disappears and no file move is attempted. This can lead to some puzzled head-scratching thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Karpagarajan : 03-27-2007 at 03:59 PM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C# .Net Tips & Tricks | oxygen | C# Programming | 85 | 01-08-2009 12:25 AM |
| SAP Tips & Tricks | leoraja8 | Operating Systems | 0 | 03-29-2008 12:11 AM |
| Visual Studio Tips & Tricks | SaravananJ | C# Programming | 197 | 12-20-2007 03:25 AM |
| PHP Tips and Tricks | Sabari | PHP Programming | 20 | 12-18-2007 05:26 AM |
| .NET tricks & Tips | Karpagarajan | VB.NET Programming | 1 | 04-23-2007 08:17 AM |
Our Partners |