sample code can't be compiled, why?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
i recently installed visual studio 2005 and wanted to run a sample c++ code at:
<p align=left><a title="http://msdn2.microsoft.com/en-us/library/ms235631(VS.80).aspx http://msdn2.microsoft.com/en-us/library/ms235631(VS.80).aspx http://msdn2.microsoft.com/en-us/library/ms235631(VS.80).aspx
<p align=left>segment "Converting from wchar_t *"
code as follow:
<p align=left> 
<p align=left><font style="background-color:#ccffcc" color="#808080 // convert_from_wchar_t.cpp
// compile with: /clr /link comsuppw.lib

#include <iostream>
#include <stdlib.h>
#include <string>

#include "atlbase.h"
#include "atlstr.h"
#include "comutil.h"

using namespace std;
using namespace System;

int main()
{
    wchar_t *orig = L"Hello, World!";
    wcout << orig << L" (wchar_t *)" << endl;

    // Convert to a char*
    size_t origsize = wcslen(orig) + 1;
    const size_t newsize = 100;
    size_t convertedChars = 0;
    char nstring[newsize];
    wcstombs_s(&convertedChars, nstring, origsize, orig, _TRUNCATE);
    strcat_s(nstring, " (char *)");
    cout << nstring << endl;

    // Convert to a _bstr_t
    _bstr_t bstrt(orig);
    bstrt += " (_bstr_t)";
    cout << bstrt << endl;

    // Convert to a CComBSTR
    CComBSTR ccombstr(orig);
    if (ccombstr.Append(L" (CComBSTR)") == S_OK)
    {
        CW2A printstr(ccombstr);
        cout << printstr << endl;
    }

    // Convert to a CString
    CString cstring(orig);
    cstring += " (CString)";
    cout << cstring << endl;

    // Convert to a basic_string
    wstring basicstring(orig);
    basicstring += L" (basic_string)";
    wcout << basicstring << endl;

    // Convert to a System:<img alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif tring
    String ^systemstring = gcnew String(orig);
    systemstring += " (System:<img alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif tring)";
    Console::WriteLine("{0}", systemstring);
    delete systemstring;
}</font>
<p align=left> 
the compiler reports error when i compiled this code, saying error LNK2028, 2019 etc
<p align=left> 
<p align=left><font color="#ff0000" size=3> I just want to ask: How should i create the project if i want to run it without any issues. Detailed project settings? </font>
<p align=left> 
<p align=left>PS. i tried Win32 Console Application and CLR Console Application, but it doesnt work at all<img src="http://forums.microsoft.com/MSDN/WebResource.axd?d=NySzF1eivP_rMoc50GQJzcvS4MHMOEKwYrCIgDtzuzlw7GsNki3H_INlfYaLgkxFSSG0MZbJ1z6uFFjZvu3APg2&t=633337194230757564

View the full article
 
Back
Top