|
Are you sure that all the items passed in to your list through the list_add() function have been created by malloc() ?
I must get a clever new signature for 2011.
|
|
|
|
|
Thanks for replying. This is what's in my main() function:
List *list = list_create();
list_add (list, "Hello");
list_dealloc (list);
|
|
|
|
|
So you are adding a pointer to a constant string which you later try to free() : result SEGV fault. You need to ensure that every pointer you pass into list_add() is pointing to a memory block that has been returned from malloc() . something like:
List *list = list_create();
char* pitem = (char*)malloc(10);
strcpy(pitem, "Hello");
list_add (list, pitem);
list_dealloc (list);
I must get a clever new signature for 2011.
|
|
|
|
|
|
Hi,
I need to send a mail to a particular email address from the application. For this purpose, I am using MAPI APIs.
Following is the code which is used in the application. This code is working properly with MS Outlook Express; however, in Lotus Notes, email ID specified in the code is not added to the "To" field of email. Other values given in the MapiRecipDesc structure is added to the email properly.
Can any one help to solve the issue?
#include "stdafx.h"
#include "Mail Application.h"
#include <MAPI.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
MapiRecipDesc sender;
MapiRecipDesc recipient;
MapiMessage note;
HMODULE hinstMapi32Dll = NULL;
if (hinstMapi32Dll == NULL)
hinstMapi32Dll = ::LoadLibraryA("MAPI32.DLL");
if (hinstMapi32Dll == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);
return -1;
}
ULONG (PASCAL *lpfnMAPISendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
lpfnMAPISendMail = (LPMAPISENDMAIL)GetProcAddress( hinstMapi32Dll, "MAPISendMail");
sender.ulReserved = 0;
sender.ulRecipClass = MAPI_ORIG;
sender.lpszName = "My Name";
sender.lpszAddress = "me@myeamil.com";
sender.ulEIDSize = 0;
sender.lpEntryID = NULL;
recipient.ulReserved = 0;
recipient.ulRecipClass = MAPI_TO;
recipient.lpszName = "Person Name";
recipient.lpszAddress = "SMTP:towhomitmayconcern@email.com";
recipient.ulEIDSize = 0;
recipient.lpEntryID = NULL;
note.ulReserved = 0;
note.lpszSubject = "Subject goes here";
note.lpszNoteText = "Message body goes here";
note.lpszMessageType = NULL;
note.lpszDateReceived = NULL;
note.lpszConversationID = NULL;
note.flFlags = 0L;
note.lpOriginator = &sender;
note.nRecipCount = 1;
note.lpRecips = &recipient;
note.nFileCount = 0;
note.lpFiles = NULL;
nRetCode = lpfnMAPISendMail( 0, 0L, ¬e, MAPI_DIALOG, 0L );
}
return nRetCode;
}
Regards,
Vinoth
modified on Wednesday, February 23, 2011 12:01 AM
|
|
|
|
|
Can any one help on this?
Regards,
Vinoth
|
|
|
|
|
Can someone tell me what's wrong with this code:
#include <stdio.h>
typedef void (*VoidFunctionPtr)(void);
void FunctionA()
{
printf("You are in Function A.\n");
}
void FunctionB()
{
printf("You are in Function B.\n");
}
int main(void)
{
VoidFunctionPtr fp = FunctionA;
fp();
}
In main(), the declaration of variable "fp" throws a C2275 error: "'VoidFunctionPtr': illegal use of this type as an expression." I don't get it. I have cross-referenced several books and internet articles. All show the same syntax. What am I missing?
|
|
|
|
|
Just tested your code with VC2010 express: compiles and runs Ok. Which compiler do you use?
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
I am using VS2010 Premium. I come from a C++ background but I need to learn what the difference is between that and standard C. To facilitate that goal I created an empty C++ project and then set the following Project Properties to disable C++ components:
Language -> Disable Language Extensions = YES (command line switch /Za)
Advanced -> Compile As = Compile As C Code (command line switch /TC)
|
|
|
|
|
Tested and works in VS6.0, 2003, 2010. What compiler are you using? Is that the only piece of code you have? can you create new project and have only this code in it? What happens if you do that?
|
|
|
|
|
I found the problem. I only posted a limited version of the code to focus the direction of the inquiry. In the context of the full code, what is going on is that the compiler expects all variables to be declared at the beginning of the function.
Original code:
#include <stdio.h>
typedef void (*VoidFunctionPtr)(void);
void FunctionA(void)
{
printf("You are in Function A.\n");
}
int main(void)
{
printf("Here is a program that does something.\n");
VoidFunctionPtr fp = FunctionA;
fp();
}
Revised code:
#include <stdio.h>
typedef void (*VoidFunctionPtr)(void);
void FunctionA(void)
{
printf("You are in Function A.\n");
}
int main(void)
{
VoidFunctionPtr fp = FunctionA;
printf("Here is a program that does something.\n");
fp();
}
I'm sure this wouldn't happen in a C++ project, but I am using compiler settings to force Standard C compilation. I come from a C++ background but I'm trying to learn the differences between C++ and standard C. I bought a book on standard C, but it references the "C99" standard, which apparently allows variables to be defined anywhere in a function. I guess the MS C compiler works on an older standard?
|
|
|
|
|
When writing C, you should probably try to declare all variables at the beginning to make sure you have compatibility with all compilers since that wasn't allowed until later on (2000?).
http://en.wikipedia.org/wiki/ANSI_C[^]
|
|
|
|
|
|
MS isn't concerned with keeping up with the latest C specs, so you'll need to avoid C99-specific features.
--Mike--
Dunder-Mifflin, this is Pam.
|
|
|
|
|
Yeah, I figured that out. Do you happen to know what (if any) standard they do conform to? I know there are several through the years.
|
|
|
|
|
If you look at the link I provided before, it states that they implemented "Microsoft Visual C++ (C90. A few features of C99)". I'm guessing you would have to dig deep to figure out what they did and didn't implement.
|
|
|
|
|
Oh, there it is. I don't know how I missed that before
|
|
|
|
|
Another difference that's easy for C++ devs to forget is the fact that C doesn't support parameters with defaults.
Example:
Valid in C++, not valid in C
int GetFoo(int HowMany=1){}
|
|
|
|
|
That's OK by me. I don't recall ever using defaults... not since college 15 years ago anyway when some homework assignment was specifically targeted at it. I do a fair amount of work in C# too, which doesn't allow defaults, so I'm used to it.
|
|
|
|
|
I use C++ A LOT, so I do forget that one sometimes... and as you've noticed, depending on the compiler (and settings), it may or may not allow it... pain in the butt!
|
|
|
|
|
First, I know this question isn't exactly ATL/WTL/STL. I see no category at all in CodeProject.com that really fits this question, so this is as close as I could get.
I'm trying to configure a project to accept only ANSI-C syntax. I have read articles that say this can be accomplished by using the /TC and /Za switches. However, I don't see where in the project properties to set them. From MSDN:
1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.
2. Click the C/C++ folder.
3. Click the Advanced property page.
4. Modify the Compile As property.
PROBLEM: When I open the Project Property pages, there is *NO* "C/C++ folder". Can anyone on this forum be more helpful than MS's own documentation? Thank you.
|
|
|
|
|
Never mind. I found the issue. Apparently the C/C++ property page doesn't show up until you have added at least one source code file. I was trying to configure it before adding any source code files. Seems kind of lame, but there we have it.
I am leaving this post up to hopefully help someone else who might run into the same problem.
|
|
|
|
|
This is probably by design. If you have an empty project then there are no C/C++ properties to show. After all, you may be intending to create the project with a different language, or even no language; Visual Studio cannot second guess your intentions.
I must get a clever new signature for 2011.
|
|
|
|
|
Well this is a tangent, but I totally disagree. The project was created by using the "Empty Project" template under the C++ templates list in the new project dialog... That implies the user intends to make a C++ project, and so at least those settings could be applied as a starting point. I mean, if I am browsing the C++ templates it's not because I intend to create a VB project or something. At least give me the minimum C++ settings as a starting point.
|
|
|
|
|
OK, maybe you should complain to Microsoft.
I must get a clever new signature for 2011.
|
|
|
|