3
Contributors
16
Replies
18
Views
7 Years
Discussion Span
Last Post by Androggles
0

Yea, i already seen that, but when i compile, i get allt hese wierd errors, that i have never seen before :S

0

Yea, i already seen that, but when i compile, i get allt hese wierd errors, that i have never seen before :S

Post your errors, maybe we can help. :icon_wink:

0

Post your errors, maybe we can help. :icon_wink:

Error E2108 : Improper use of typedef 'HRESULT' in function main()
Error E2379 : Statement missing ; in function main()
Error E2141 : Declaration syntax error in function main()
Error E2139 : Declaration missing ; in function main()
Error E2190 : Unexpected }

I do know some of the errors, but when i correct them, i judt get even more errors...

0

They seem like pretty straightforward errors, if you post the exact code you're using I can hopefully highlight your mistakes.

You mean like all of the program, or just the shortcut code?

0

Depends on how big the program is. Post enough code to recreate the exact same errors you're getting if possible.

Edited by William Hemsworth: n/a

0
#include <iostream.h>
#include <windows.h>

int spg1;//Spørgsmål 1
int spg2;//Spørgsmål 2
int spg3;//Spørgsmål 3

int start = 1;

int main()
{
FreeConsole();

HRESULT CreateShortcut(/*in*/ LPCTSTR lpszFileName; 
                    /*in*/ LPCTSTR lpszDesc, 
                    /*in*/ LPCTSTR lpszShortcutPath)
{
    HRESULT hRes = E_FAIL;
    DWORD dwRet = 0;
    CComPtr<IShellLink> ipShellLink;
        // buffer that receives the null-terminated string 
        // for the drive and path
    TCHAR szPath[MAX_PATH];    
        // buffer that receives the address of the final 
        //file name component in the path
    LPTSTR lpszFilePart;    
    WCHAR wszTemp[MAX_PATH];
        
    // Retrieve the full path and file name of a specified file
    dwRet = GetFullPathName(lpszFileName, 
                       sizeof(szPath) / sizeof(TCHAR), 
                       szPath, &lpszFilePart);
    if (!dwRet)                                        
        return hRes;

    // Get a pointer to the IShellLink interface
    hRes = CoCreateInstance(CLSID_ShellLink,
                            NULL, 
                            CLSCTX_INPROC_SERVER,
                            IID_IShellLink,
                            (void**)&ipShellLink);

    if (SUCCEEDED(hRes))
    {
        // Get a pointer to the IPersistFile interface
        CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);

        // Set the path to the shortcut target and add the description
        hRes = ipShellLink->SetPath(szPath);
        if (FAILED(hRes))
            return hRes;

        hRes = ipShellLink->SetDescription(lpszDesc);
        if (FAILED(hRes))
            return hRes;

        // IPersistFile is using LPCOLESTR, so make sure 
                // that the string is Unicode
#if !defined _UNICODE
        MultiByteToWideChar(CP_ACP, 0, 
                       lpszShortcutPath, -1, wszTemp, MAX_PATH);
#else
        wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
#endif

        // Write the shortcut to disk
        hRes = ipPersistFile->Save(wszTemp, TRUE);
    }

    return hRes;
}

//Spørgsmål 1
cout << "Velkommen til denne quiz om: Mia!" << endl;
Sleep(5000);
cout << "Hvor befinder Mia sig lige nu?" << endl;
cout << "1. I Koebenhavn" << endl;
cout << "2. I Frederikshavn" << endl;
cout << "3. I Florida" << endl;
cout << "SKRIV VENLIGST ET SVARNR: ";
cin >> spg1;

if(spg1 == 1)
{
	//Spørgsmål 2
	cout << "KORREKT!\n" << endl;
	cout << "Er Mia liderlig? :D" << endl;
	cout << "1. Ja" << endl;
	cout << "2. Nej" << endl;
	cout << "3. Maaske" << endl;
	cout << "SKRIV VENLIGST ET SVARNR: ";
	cin >> spg2;
		if(spg2 == 1)

It goes on with some more if-else's down, but that was too much to post ;)
But this is pretty much it...

0

I think the main problem is you haven't really learned the basics of C++, such as scopes, functions, and layout. Before trying something on this level, maybe read a few more tutorials. More specifically.. the structure of a program, Scopes and Functions.

The main problem in the code you provided is that you have a function inside your main function. The CreateShortcut function should be totally seperate from the rest of the code.

0

I think the main problem is you haven't really learned the basics of C++, such as scopes, functions, and layout. Before trying something on this level, maybe read a few more tutorials. More specifically.. the structure of a program, Scopes and Functions.

The main problem in the code you provided is that you have a function inside your main function. The CreateShortcut function should be totally seperate from the rest of the code.

Okay, I will certainly read what you have linked there, already did a little, and already seems to lighten up, but i still can't figure out.
I get a lot of errors, but now it is some new ones:
Error E2108 lol2.cpp 6: Improper use of typedef 'LPCTSTR'
Error E2293 lol2.cpp 6: ) expected
Error E2238 lol2.cpp 8: Multiple declaration for 'LPCTSTR'
Error E2344 c:\Borland\Bcc55\include\winnt.h 272: Earlier declaration of 'LPCTSTR'
Error E2141 lol2.cpp 8: Declaration syntax error

I dont know if you could make a 'quick' runthrough about what i need to do?

0

Well these errors don't seem as bad, but I'm not much help until I see the improved code again, those just look like small syntax errors, but I can't tell for sure.

0

Okay, i'm posting the exact code, as it looks right now here. And if you want, i have attached the cpp file.

#include <iostream.h>
#include <windows.h>

int start = 1;

HRESULT CreateShortcut(/*in*/ LPCTSTR lpszFileName; 
                    /*in*/ LPCTSTR lpszDesc, 
                    /*in*/ LPCTSTR lpszShortcutPath)
{
    HRESULT hRes = E_FAIL;
    DWORD dwRet = 0;
    CComPtr<IShellLink> ipShellLink;
        // buffer that receives the null-terminated string 
        // for the drive and path
    TCHAR szPath[MAX_PATH];    
        // buffer that receives the address of the final 
        //file name component in the path
    LPTSTR lpszFilePart;    
    WCHAR wszTemp[MAX_PATH];
        
    // Retrieve the full path and file name of a specified file
    dwRet = GetFullPathName(lpszFileName, 
                       sizeof(szPath) / sizeof(TCHAR), 
                       szPath, &lpszFilePart);
    if (!dwRet)                                        
        return hRes;

    // Get a pointer to the IShellLink interface
    hRes = CoCreateInstance(CLSID_ShellLink,
                            NULL, 
                            CLSCTX_INPROC_SERVER,
                            IID_IShellLink,
                            (void**)&ipShellLink);

    if (SUCCEEDED(hRes))
    {
        // Get a pointer to the IPersistFile interface
        CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);

        // Set the path to the shortcut target and add the description
        hRes = ipShellLink->SetPath(szPath);
        if (FAILED(hRes))
            return hRes;

        hRes = ipShellLink->SetDescription(lpszDesc);
        if (FAILED(hRes))
            return hRes;

        // IPersistFile is using LPCOLESTR, so make sure 
                // that the string is Unicode
#if !defined _UNICODE
        MultiByteToWideChar(CP_ACP, 0, 
                       lpszShortcutPath, -1, wszTemp, MAX_PATH);
#else
        wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
#endif

        // Write the shortcut to disk
        hRes = ipPersistFile->Save(wszTemp, TRUE);
    }

    return hRes;
}

int main()
{
FreeConsole();

while(start == 1)
{
	if(spg1 == 1)
{
	//Spørgsmål 2
	cout << "KORREKT!\n" << endl;
	cout << "Er Mia? :D" << endl;
	cout << "1. Ja" << endl;
	cout << "2. Nej" << endl;
	cout << "3. Maaske" << endl;
	cout << "SKRIV VENLIGST ET SVARNR: ";
	cin >> spg2;
		if(spg2 == 1)
		{
		//Spørgsmål 3
		cout << "KORREKT!\n" << endl;
		cout << "Er Mia freak? ;)" << endl;
		cout << "1. Ja" << endl;
		cout << "2. Nej" << endl;
		cout << "3. Maaske" << endl;
		cout << "SKRIV VENLIGST ET SVARNR: ";
		cin >> spg3;
			if(spg3 == 3)
			{
			//Spørgsmål 4
			cout << "KORREKT!" << endl;
			cout << "Er Mia sej?" << endl;
			cout << "1. Ja" << endl;
			cout << "2. Nej" << endl;
			cout << "3. Piger er ikke seje!" << endl;
			cout << "SKRIV VENLIGST ET SVARNR: ";
			cin  >> spg4;
				if(spg4 == 3)
				{
				//Spørgsmål 5
				cout << "KORREKT!" << endl;
				cout << "Hvor mange har Mia? xD" << endl;
				cout << "1. 1" << endl;
				cout << "2. Omkring 5" << endl;
				cout << "3. 100000000" << endl;
				cout << "4. For mange! :D" << endl;
				cout << "SKRIV VENLIGST ET SVARNR: ";
				cin >> spg5;
					if(spg5 == 4)
					{
					cout << "KORREKT!" << endl;
					cout << "Tillykke, du har nu gennemfort denne mega aandsvage quiz!" << endl;
					cout << "Har du ideer til spoersgmål så skriv lige! ;)" << endl;
					Sleep(20000);
					}
					else
					{
					cout << "FORKERT";
					Sleep(5000);
					}
				}
				else
				{
				cout << "FORKERT!";
				Sleep(5000);
				}
			}
			else
			{
			cout << "FORKERT!";
			Sleep(5000);
			}
		
		}
		else
		{
		cout << "FORKERT!";
		Sleep(5000);
		}
}
else
{
	cout << "FORKERT!";
	Sleep(5000);
}
}
}
}
Attachments
#include <iostream.h>
#include <windows.h>

int start = 1;

HRESULT CreateShortcut(/*in*/ LPCTSTR lpszFileName; 
                    /*in*/ LPCTSTR lpszDesc, 
                    /*in*/ LPCTSTR lpszShortcutPath)
{
    HRESULT hRes = E_FAIL;
    DWORD dwRet = 0;
    CComPtr<IShellLink> ipShellLink;
        // buffer that receives the null-terminated string 
        // for the drive and path
    TCHAR szPath[MAX_PATH];    
        // buffer that receives the address of the final 
        //file name component in the path
    LPTSTR lpszFilePart;    
    WCHAR wszTemp[MAX_PATH];
        
    // Retrieve the full path and file name of a specified file
    dwRet = GetFullPathName(lpszFileName, 
                       sizeof(szPath) / sizeof(TCHAR), 
                       szPath, &lpszFilePart);
    if (!dwRet)                                        
        return hRes;

    // Get a pointer to the IShellLink interface
    hRes = CoCreateInstance(CLSID_ShellLink,
                            NULL, 
                            CLSCTX_INPROC_SERVER,
                            IID_IShellLink,
                            (void**)&ipShellLink);

    if (SUCCEEDED(hRes))
    {
        // Get a pointer to the IPersistFile interface
        CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);

        // Set the path to the shortcut target and add the description
        hRes = ipShellLink->SetPath(szPath);
        if (FAILED(hRes))
            return hRes;

        hRes = ipShellLink->SetDescription(lpszDesc);
        if (FAILED(hRes))
            return hRes;

        // IPersistFile is using LPCOLESTR, so make sure 
                // that the string is Unicode
#if !defined _UNICODE
        MultiByteToWideChar(CP_ACP, 0, 
                       lpszShortcutPath, -1, wszTemp, MAX_PATH);
#else
        wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
#endif

        // Write the shortcut to disk
        hRes = ipPersistFile->Save(wszTemp, TRUE);
    }

    return hRes;
}

int main()
{
FreeConsole();

while(start == 1)
{
	if(spg1 == 1)
{
	//Sprgsml 2
	cout << "KORREKT!\n" << endl;
	cout << "Er Mia liderlig? :D" << endl;
	cout << "1. Ja" << endl;
	cout << "2. Nej" << endl;
	cout << "3. Maaske" << endl;
	cout << "SKRIV VENLIGST ET SVARNR: ";
	cin >> spg2;
		if(spg2 == 1)
		{
		//Sprgsml 3
		cout << "KORREKT!\n" << endl;
		cout << "Er Mia freak? ;)" << endl;
		cout << "1. Ja" << endl;
		cout << "2. Nej" << endl;
		cout << "3. Maaske" << endl;
		cout << "SKRIV VENLIGST ET SVARNR: ";
		cin >> spg3;
			if(spg3 == 3)
			{
			//Sprgsml 4
			cout << "KORREKT!" << endl;
			cout << "Er Mia sej?" << endl;
			cout << "1. Ja" << endl;
			cout << "2. Nej" << endl;
			cout << "3. Piger er ikke seje!" << endl;
			cout << "SKRIV VENLIGST ET SVARNR: ";
			cin  >> spg4;
				if(spg4 == 3)
				{
				//Sprgsml 5
				cout << "KORREKT!" << endl;
				cout << "Hvor mange har Mia knaldet med? xD" << endl;
				cout << "1. 1" << endl;
				cout << "2. Omkring 5" << endl;
				cout << "3. 100000000" << endl;
				cout << "4. For mange! :D" << endl;
				cout << "SKRIV VENLIGST ET SVARNR: ";
				cin >> spg5;
					if(spg5 == 4)
					{
					cout << "KORREKT!" << endl;
					cout << "Tillykke, du har nu gennemfort denne mega aandsvage quiz!" << endl;
					cout << "Har du ideer til spoersgml s skriv lige! ;)" << endl;
					Sleep(20000);
					}
					else
					{
					cout << "FORKERT";
					Sleep(5000);
					}
				}
				else
				{
				cout << "FORKERT!";
				Sleep(5000);
				}
			}
			else
			{
			cout << "FORKERT!";
			Sleep(5000);
			}
		
		}
		else
		{
		cout << "FORKERT!";
		Sleep(5000);
		}
}
else
{
	cout << "FORKERT!";
	Sleep(5000);
}
}
}
}
0

Typo (semicolon in place of a comma):

HRESULT CreateShortcut(/*in*/ LPCTSTR lpszFileName[B];[/B] 
                    /*in*/ LPCTSTR lpszDesc, 
                    /*in*/ LPCTSTR lpszShortcutPath)

Have you #included all necessary headers?

[edit]Errors I see after minor tweaking:

main.cpp: In function `HRESULT CreateShortcut(const TCHAR*, const TCHAR*, const TCHAR*)':
main.cpp:13: error: `CComPtr' was not declared in this scope
main.cpp:13: error: `IShellLink' was not declared in this scope
main.cpp:13: error: `ipShellLink' was not declared in this scope
main.cpp:30: error: `CLSID_ShellLink' was not declared in this scope
main.cpp:33: error: `IID_IShellLink' was not declared in this scope
main.cpp:39: error: `CComQIPtr' was not declared in this scope
main.cpp:39: error: expected primary-expression before '>' token
main.cpp:39: error: `ipPersistFile' was not declared in this scope
main.cpp:39: warning: unused variable 'CComQIPtr'
main.cpp:13: warning: unused variable 'CComPtr'
main.cpp:13: warning: unused variable 'IShellLink'
main.cpp:30: warning: unused variable 'CLSID_ShellLink'
main.cpp:33: warning: unused variable 'IID_IShellLink'
main.cpp: In function `int main()':
main.cpp:72: error: `spg1' was not declared in this scope
main.cpp:81: error: `spg2' was not declared in this scope
main.cpp:91: error: `spg3' was not declared in this scope
main.cpp:101: error: `spg4' was not declared in this scope
main.cpp:112: error: `spg5' was not declared in this scope
main.cpp:72: warning: unused variable 'spg1'
main.cpp: At global scope:
main.cpp:152: error: expected declaration before '}' token
*** Errors occurred during this build ***

Edited by Dave Sinkula: n/a

0

Typo (semicolon in place of a comma):

HRESULT CreateShortcut(/*in*/ LPCTSTR lpszFileName[B];[/B] 
                    /*in*/ LPCTSTR lpszDesc, 
                    /*in*/ LPCTSTR lpszShortcutPath)

Have you #included all necessary headers?

[edit]Errors I see after minor tweaking:

Yes, all is included, but now i see that they are not in the file i attached.

0

Okay, i fixed some of it, but these last errors, i dont know how to fix:
Error E2451 lol2.cpp 16: Undefined symbol 'CComPtr' in function CreateShortcut(const char *,const char *,const char *)
Error E2108 lol2.cpp 16: Improper use of typedef 'IShellLinkA' in function CreateShortcut(const char *,const char *,const char *)
Error E2451 lol2.cpp 16: Undefined symbol 'ipShellLink' in function CreateShortcut(const char *,const char *,const char *)
Error E2451 lol2.cpp 42: Undefined symbol 'CComQIPtr' in function CreateShortcut(const char *,const char *,const char *)
Error E2108 lol2.cpp 42: Improper use of typedef 'IPersistFile' in function CreateShortcut(const char *,const char *,const char *)
Error E2268 lol2.cpp 42: Call to undefined function 'ipPersistFile' in function CreateShortcut(const char *,const char *,const char *)
Error E2288 lol2.cpp 63: Pointer to structure required on left side of -> or ->* in function CreateShortcut(const char *,const char *,const char *)
Warning W8057 lol2.cpp 67: Parameter 'lpszDesc' is never used in function CreateShortcut(const char *,const char *,const char *)
Error E2141 lol2.cpp 74: Declaration syntax error in function main()
Error E2139 lol2.cpp 97: Declaration missing ; in function main()
Error E2190 lol2.cpp 97: Unexpected }

Edited by Androggles: n/a

0

Okay, during the night i have been reading the links you posted, and i have come down to these few errors, that i cant find:

Error E2108 lol2.cpp 10: Improper use of typedef 'LPCTSTR'
Error E2293 lol2.cpp 10: ) expected
Error E2141 lol2.cpp 10: Declaration syntax error

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.