can't find problem with code

Apr 15, 2013 at 9:24am
when i try build my program i get this error:
fatal error C1075: end of file found before the left brace '{'

i know it means i'm missing a bracket somewhere but there is only 6 brackets in the program and there are all there. if i click the error it just brings me to end of the program and if i add an extra bracket it gives another error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include "ContextExample_h.h"

// Write a formatted error message to std::cerr.
DWORD HandleError(const char* szFunction, DWORD dwError)
{
   void* pBuffer = NULL;
   FormatMessage(
      FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
      FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
      NULL,
      dwError,
      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
      LPSTR(&pBuffer),
      0,
      NULL);

   std::cerr << szFunction << " failed. "
      << (pBuffer ? LPCSTR(pBuffer) : "Unknown error. ")
      << "(" << dwError << ")" << std::endl;
   LocalFree(pBuffer);
   return dwError;
}

int main()
{
   RPC_STATUS status;
   unsigned char* szStringBinding = NULL;

   std::clog << "Calling RpcStringBindingCompose" << std::endl;
   // Creates a string binding handle.
   // This function is nothing more than a printf.
   // Connection is not done here.
   status = RpcStringBindingCompose(
      NULL, // UUID to bind to.
      reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), // Use TCP/IP protocol.
      reinterpret_cast<unsigned char*>("localhost"), // TCP/IP network address to use.
      reinterpret_cast<unsigned char*>("4747"), // TCP/IP port to use.
      NULL, // Protocol dependent network options to use.
      &szStringBinding); // String binding output.
   if (status)
      return HandleError("RpcStringBindingCompose", status);

   handle_t hBinding = NULL;

   std::clog << "Calling RpcBindingFromStringBinding" << std::endl;
   // Validates the format of the string binding handle and converts
   // it to a binding handle.
   // Connection is not done here either.
   status = RpcBindingFromStringBinding(
      szStringBinding, // The string binding to validate.
      &hBinding); // Put the result in the explicit binding handle.
   if (status)
      return HandleError("RpcBindingFromStringBinding", status);

   std::clog << "Calling RpcStringFree" << std::endl;
   // Free the memory allocated by a string.
   status = RpcStringFree(
      &szStringBinding); // String to be freed.
   if (status)
      return HandleError("RpcStringFree", status);

   std::clog << "Calling RpcEpResolveBinding" << std::endl;
   // Resolves a partially-bound server binding handle into a
   // fully-bound server binding handle.
   status = RpcEpResolveBinding(hBinding, ContextExample_v1_0_c_ifspec);
   if (status)
      return HandleError("RpcEpResolveBinding", status);

   RpcTryExcept
   {
      std::clog << "Calling Open" << std::endl;
      // Open the context handle.
      CONTEXT_HANDLE hContext = Open(hBinding, "Hello Context World!");

      std::cout << "Press enter to call Output" << std::endl;
      std::cin.get();

      std::clog << "Calling Output" << std::endl;
      // Calls the RPC function. The hBinding binding handle
      // is used explicitly.
      Output(hContext);

      std::cout << "Press enter to call Close" << std::endl;
      std::cin.get();

      std::clog << "Calling Close" << std::endl;
      // Close the context handle.
      Close(&hContext);
   }
}   

Apr 15, 2013 at 9:33am
Check your "ContextExample_h.h" file. Error might be there.
Apr 15, 2013 at 9:36am
there's no error in the header file
Apr 15, 2013 at 9:39am
check the macro - RpcTryExcept. this is just a starting brace


1
2
3
4
//rpc.h
#define RpcTryExcept \
    __try \
        { 




you need to end this by its closing brace. look for examples on how to use it.
Apr 15, 2013 at 9:47am
there's nothing wrong with that file either...
Apr 15, 2013 at 9:50am
post header file.
Apr 15, 2013 at 9:51am
ok this is ContextExample_h.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif

#include "rpc.h"
#include "rpcndr.h"

#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__


#ifndef __ContextExample_h_h__
#define __ContextExample_h_h__

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

/* Forward Declarations */ 

#ifdef __cplusplus
extern "C"{
#endif 


#ifndef __ContextExample_INTERFACE_DEFINED__
#define __ContextExample_INTERFACE_DEFINED__

/* interface ContextExample */
/* [explicit_handle][version][uuid] */ 

typedef /* [context_handle] */ void *CONTEXT_HANDLE;

CONTEXT_HANDLE Open( 
    /* [in] */ handle_t hBinding,
    /* [string][in] */ const char *szString);

void Output( 
    /* [in] */ CONTEXT_HANDLE hContext);

void Close( 
    /* [out][in] */ CONTEXT_HANDLE *phContext);



extern RPC_IF_HANDLE ContextExample_v1_0_c_ifspec;
extern RPC_IF_HANDLE ContextExample_v1_0_s_ifspec;
#endif /* __ContextExample_INTERFACE_DEFINED__ */

/* Additional Prototypes for ALL interfaces */

void __RPC_USER CONTEXT_HANDLE_rundown( CONTEXT_HANDLE );

/* end of Additional Prototypes */

#ifdef __cplusplus
}
#endif

#endif 
Last edited on Apr 15, 2013 at 9:51am
Apr 15, 2013 at 9:57am
http://msdn.microsoft.com/en-us/library/windows/desktop/aa378485%28v=vs.85%29.aspx
All RpcTryExcept statements must be terminated by the RpcEndExcept statement.

Your problem

Or you can look into how this unnesesary macro is defined and try to balance braces...
Or alternatively use standard ways to handle exceptions
Last edited on Apr 15, 2013 at 10:00am
Apr 15, 2013 at 10:05am
Yea miinipaa's right.
If i put another closing brace at the bottom of your cpp file the error changes to:
Error: expected __except or __finally
Apr 15, 2013 at 10:07am
All RpcTryExcept statements must be terminated by the RpcEndExcept statement.

does the code not do this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define RpcTryExcept \
    __try \
        {

// trystmts

#define RpcExcept(expr) \
        } \
    __except (expr) \
        {

// exceptstmts

#define RpcEndExcept \
        }

#define RpcTryFinally \
    __try \
        {

// trystmts

#define RpcFinally \
        } \
    __finally \
        {

// finallystmts

#define RpcEndFinally \
        } 
Apr 15, 2013 at 10:11am
just comment out your 'RpcTryExcept{'
Apr 15, 2013 at 10:16am
just comment out your 'RpcTryExcept{'

in the code in the first post?
Apr 15, 2013 at 10:18am
yup.
lines 70.71 and 90.
Last edited on Apr 15, 2013 at 10:19am
Apr 15, 2013 at 1:31pm
those are the # defines. your code is actually doing this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
main()
{
__try
{


//some code here






} //main ends 
Topic archived. No new replies allowed.