Click here to Skip to main content
15,897,315 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Using a RecordView in Dialog Pin
David Crow23-Jan-04 10:14
David Crow23-Jan-04 10:14 
GeneralDialog dissapears... ? Pin
Calder23-Jan-04 11:51
Calder23-Jan-04 11:51 
GeneralRe: Dialog dissapears... ? Pin
David Crow26-Jan-04 2:22
David Crow26-Jan-04 2:22 
GeneralRetrieving a bitmap using a URL. using a pluggable protocol Pin
Member 1329456923-Jan-04 3:43
Member 1329456923-Jan-04 3:43 
GeneralRe: Retrieving a bitmap using a URL. using a pluggable protocol Pin
valikac23-Jan-04 5:42
valikac23-Jan-04 5:42 
GeneralRe: Retrieving a bitmap using a URL. using a pluggable protocol Pin
Member 1329456923-Jan-04 7:03
Member 1329456923-Jan-04 7:03 
GeneralRe: Retrieving a bitmap using a URL. using a pluggable protocol Pin
l a u r e n23-Jan-04 14:39
l a u r e n23-Jan-04 14:39 
GeneralApplication Error: The Instruction at --- pReturnVal = (char*) calloc(strlen(s)+1,sizeof(char)); Pin
AssemblySoft23-Jan-04 3:27
AssemblySoft23-Jan-04 3:27 
In debug mode this code works fine, however when i switch to release i get:

Application Error: The Instruction at 0x77fc9865 referenced memory at: 0x7c45732 The memory could not be read.

I have looked and found this is probably to do with array bounds, but i can't see anything wrong with the code below.

Help would be appreciated D'Oh! | :doh:


If i just return s then everything works fine, however this would be returning a local variable and the compiler will flag the warning.


char * get_font_string(HFONT hFont, HWND hwnd)
{
char s[1000];
TEXTMETRIC tm;
char face_name[200];

HDC hdc = GetDC(hwnd);

SelectObject(hdc,hFont);
GetTextMetrics(hdc,&tm);
GetTextFace(hdc,200,face_name);

if (!stricmp(face_name,"FixedSys"))
strcpy(face_name,"System");

if (!strcmp(face_name,"System"))
{
strcpy(face_name,"FixedSys");
tm.tmWeight = FW_NORMAL;
}


sprintf(s,"%d %d %d %d %d %u %u %u %u %u %u %u %u %s",
tm.tmHeight,tm.tmAveCharWidth,0, 0, tm.tmWeight,
tm.tmItalic, tm.tmUnderlined, tm.tmStruckOut, tm.tmCharSet,
0,0,DEFAULT_QUALITY, tm.tmPitchAndFamily,
face_name);


ReleaseDC(hwnd,hdc);

pReturnVal = (char*) calloc(strlen(s)+1,sizeof(char));
strcpy(pReturnVal,s);

//return s
return pReturnVal;Unsure | :~
}


later in code:

strcpy(font_string,get_font_string(f.hFont,f.hwnd));
free(pReturnVal);



GeneralRe: Application Error: The Instruction at --- pReturnVal = (char*) calloc(strlen(s)+1,sizeof(char)); Pin
Ian Darling23-Jan-04 3:58
Ian Darling23-Jan-04 3:58 
GeneralLink Error Pin
BrockVnm23-Jan-04 2:30
BrockVnm23-Jan-04 2:30 
GeneralRe: Link Error Pin
P_JAYAPRAKASH23-Jan-04 2:56
P_JAYAPRAKASH23-Jan-04 2:56 
GeneralRe: Link Error Pin
BrockVnm23-Jan-04 3:52
BrockVnm23-Jan-04 3:52 
GeneralRe: Link Error Pin
Michael Dunn23-Jan-04 4:42
sitebuilderMichael Dunn23-Jan-04 4:42 
GeneralRe: Link Error Pin
BrockVnm23-Jan-04 5:09
BrockVnm23-Jan-04 5:09 
Generalmicroseconds Pin
lpRomang23-Jan-04 2:09
lpRomang23-Jan-04 2:09 
GeneralRe: microseconds Pin
фил23-Jan-04 2:30
фил23-Jan-04 2:30 
GeneralRe: microseconds Pin
lpRomang23-Jan-04 3:54
lpRomang23-Jan-04 3:54 
GeneralRe: microseconds Pin
RChin23-Jan-04 3:53
RChin23-Jan-04 3:53 
GeneralRe: microseconds Pin
dknoble23-Jan-04 6:48
dknoble23-Jan-04 6:48 
GeneralRe: microseconds Pin
Marcello25-Jan-04 10:50
Marcello25-Jan-04 10:50 
GeneralRe: microseconds Pin
dknoble26-Jan-04 2:28
dknoble26-Jan-04 2:28 
GeneralRe: microseconds Pin
Marcello26-Jan-04 6:08
Marcello26-Jan-04 6:08 
GeneralOn_exit and signal Pin
Anonymous23-Jan-04 1:34
Anonymous23-Jan-04 1:34 
GeneralRichEdit Pin
edwinak23-Jan-04 1:24
edwinak23-Jan-04 1:24 
GeneralRe: RichEdit Pin
CodeBrain23-Jan-04 1:35
CodeBrain23-Jan-04 1:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.