|
I don't do a lot of non-MFC these days because I find the classes so useful. It's also hard to show something useful without it containing a lot of stuff that's specific to my application and would make no sense to you. CDBException is for errors coming from CDatabase and CRecordset classes.
Here's my general exception catcher in the main loop of my application. Ignore things that are related to sending messages back to the user (client / server app).
catch (CException * cfe)
{
char exceptBuf[255];
CString ts;
CString ccnum;
if (!cfe->GetErrorMessage(exceptBuf, sizeof(exceptBuf)))
exceptBuf[0] = '\0';
#ifdef _DEBUG
AfxMessageBox(exceptBuf);
#endif
if (claim_check != NULL)
ccnum = claim_check->getClaimCheck();
else
ccnum = "000000";
ts.Format("Internal Exception Trap - %s", exceptBuf);
TheLogFile->LogThis(ccnum + CString(" : ") + ts);
sendErrorToGUI(ts, E_DEFAULTERROR, TheCommCenter, claim_check, parsed_request, inputConfig);
}
|
|
|
|
|
The first post was very helpful, I realized it was the same as vb, and I had to find the right exception, in which my case was exception literally.
I can't reproduce the error so I can test catch it, but I did the messagebox which is good enough for now. I don't expect it to ever trigger the catch anymore, since fixing all my errors.
Thanks Chunk
|
|
|
|
|
Unfortunately CoCreateInstance isn't a C++ function so it won't throw exceptions - unless someone's implemented a wrapper or something around the function that we can't see in your example.
For COM and OLE functions you have to pull apart the HRESULT return value, preferably using the Microsoft macros and/or call GetLastError/FormatMessage. It's a pain in the bum but COM and OLE are pretty old now and MS haven't quite managed to kill it off or hide it yet.
What the various return values mean can be found here[^].
Edit for English fail.
|
|
|
|
|
I didn't know it was old school, and thought it was the current way to talk to IIS 7+ web server.
It must of stopped due to one of the previous errors I made earlier. So I will use the hr check instead.
Thanks for the heads up on that.
hr = CoCreateInstance( __uuidof( AppHostWritableAdminManager ), NULL,
CLSCTX_INPROC_SERVER, __uuidof( IAppHostWritableAdminManager ), (void**) &pMgr);
if ( FAILED( hr ) )
goto CLEANUP;
|
|
|
|
|
hello guys... This error has something to do with linking. I have a static library (which contains some virtual functions) and I have taken following steps to add it to my project.
- Project Name -> Add -> Existing Item . Chose and included header file.
- Project Name -> Properties -> C/C++ -> General -> Additional Include Directories . Navigated to the folder containing the header file.
- Project Name -> Properties -> Linker -> Input -> Additional Dependencies . Gave the path including the library_name.lib
Until here, it compiles successfully. But when I derive a class from a class in this header file, it starts giving this error like: Error LNK 2001 - Unresolved External Symbols? Whats wrong with this approach? Thanks for any input.
This world is going to explode due to international politics, SOON.
modified 7-May-12 8:54am.
|
|
|
|
|
I'm not sure, but the specification of Additional Dependencies may only affect the bulding and re-building of your project. I think you have to specify additional linker directories to use and also additional libraries to include. This are usually in the same place or tab as the Additional Dependencies.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
This looks like it should work... in the header that you have included, make sure you don't have to #define anything to specify that you are using the library instead of building it. Sometimes developers use the same exact header file to build the library than what others would use to import the library and just use pre-processor directives to tell the difference.
What are the external symbols that it can't find? Are they defined in the header?
|
|
|
|
|
Albert Holguin wrote: What are the external symbols that it can't find? Are they defined in the header?
Yes. They are virtual functions and are defined in the header file.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Regular "virtual" or "pure virtual"? Makes a difference. Please post the definition from the header file so we can see.
|
|
|
|
|
Well they are regular virtual functions. An example of them can be like this
virtual void OnAdd(double n1, double n2);
virtual void OnSub(double n1, double n2);
virtual void OnMul(double n1, double n2);
virtual void OnMul(double n1, double n2);
Now I have implemented a similar application whose architecture is exactly same. Four arithmetic virtual functions in a library which I later included in the project. Then I derived a class from this lib's class and overrided those functions. It worked successfully.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
I hate to ask a question that should have been asked first. What is the exact error message. Which "symbol" is unresolved, the one in the base class or the one in your derived class? If it's the former, then the problem is that your library is not included in the linker section as an additional library. If it's the latter, then the problem is in your code and the definition of the overridden members.
|
|
|
|
|
That's in base class. But it is solved by strange method. What I did is:
- I overrided all the virtual functions in the the derived class (although left function bodies blank ).
This solved my problem. But I am thinking why it should have been a problem. I mean usually virtual functions are meant to be overriden, what if I don't want to override them at a particular point.
Well it is becoming messy, I am happy that my problem is solved for now.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
You didn't "solve" the problem, you only made the "symptoms" go away. Now you have empty functions overriding ones that may have done something useful, as you've discovered.
If it can't find the functions in the library then:
1) you didn't list the library as an input to the linker (both debug and release)
2) you are feeding in the wrong library
3) they are not in the library
You need to go back to the person / source that gave you the library and ask them about the contents and why you are having this particular problem. I'm going to stop offering suggestions on this one.
|
|
|
|
|
As I stated earlier, I made a similar application (calculator) with exactly same architecture and it worked. Well I did ask him. But that poor guy could not answer me. He could only give a possible solution that was: may be its due to the character set.
- The library was made using: Not Set.
- While my solution was made using: Use Unicode Character set.
But he was not sure what the problem could be. Anyway, thank you very much for your time.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Hi,
As some of you may already be aware from some of my post I am a MainFrame Assembler programmer trying to get into the Windows MFC platform
This presented me with a number of challanges to name two
1) Understanding Object Oriented as opposed to procedural coding
2) thinking of text as fonts instead of bytes oriented characters
Well it seems that RichEdit interface deals with characters e.g ( SetSel API) instead
of fonts
So Here is my problem listed below is the text I am displaying in a RichEdit window
000000 00000 004A4 10 TESTA CSECT
11 TESTA AMODE 31
12 TESTA RMODE ANY
13 YREGS
0 00000 15+R0 EQU 0 01-YREGS
00001 16+R1 EQU 1 01-YREGS
00002 17+R2 EQU 2 01-YREGS
00003 18+R3 EQU 3 01-YREGS
00004 19+R4 EQU 4 01-YREGS
00005 20+R5 EQU 5 01-YREGS
00006 21+R6 EQU 6 01-YREGS
00007 22+R7 EQU 7 01-YREGS
00008 23+R8 EQU 8 01-YREGS
00009 24+R9 EQU 9 01-YREGS
0000A 25+R10 EQU 10 01-YREGS
0000B 26+R11 EQU 11 01-YREGS
0000C 27+R12 EQU 12 01-YREGS
0000D 28+R13 EQU 13 01-YREGS
0000E 29+R14 EQU 14 01-YREGS
0000F 30+R15 EQU 15 01-YREGS
0 00007 32 XLNK EQU R7
_ 000000 33 ARNDCOPY DS 0H
_ 000000 90EC D00C 0000C 34 STM R14,R12,12(R13)
_ 000004 18CF 35 LR R12,R15
R:C 00000 36 USING TESTA,R12
37 * HERCDIE LINKAGE=SVC
_ 000006 18ED 38 LR R14,R13
_ 000008 41D0 C314 00314 39 LA R13,SAVEAREA
_ 00000C 50E0 C318 00318 40 ST R14,SAVEAREA+4
_ 000010 50C0 C38C 0038C 41 ST R12,WORKFLD
_ 000014 F384 C391 C38C 00391 0038C 42 UNPK WORFLD1,WORKFLD(5)
_ 00001A DC08 C391 C39A 00391 0039A 43 TR WORFLD1,TR_TBL
44 LOAD EP=TESTB
_ 000020 46+ CNOP 0,4 @YA29363 01-LOAD
_ 000020 4DF0 C02C 0002C 47+ BAS 15,LOAD2_0002 BRANCH AROUND CONSTANT(S) 01-LOAD
000024 48+LD2_0002 DS 0H 01-LOAD
000024 E3C5E2E3C2404040 49+LE2_0002 DC CL8'TESTB' ENTRY POINT NAME 01-LOAD
00002C 50+LOAD2_0002 DS 0H 01-LOAD
_ 00002C 4100 F000 00000 51+ LA 0,LE2_0002-LD2_0002(,15) ADDR OF PARAMETER 01-LOAD
_ 000030 1B11 52+ SR 1,1 SHOW NO DCB PRESENT 01-LOAD
_ 000032 0A08 53+ SVC 8 01-LOAD
_ 000034 D207 C37B C391 0037B 00391 54 MVC STARTS,WORFLD1
55 * WTOR TEXT=(START_ADDR,REPLY,1,ECB_REPLY)
56 * WAIT ECB=ECB_REPLY
1 Page 4
I am trying to highlight the first Mainframe executable line which is the line with
the following text STM R14,R12,12(R13)
Here is the code I use to that
SetSel(0,0);
FINDTEXTEX ft;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = (LPSTR) "_ ";
long n = FindText(FR_DOWN|FR_MATCHCASE | FR_WHOLEWORD, &ft);
long l = LineLength(n);
From my understanding all return codes from the richedit api 0 character based
however When step thru the code of the FindText api the return code is some huge number X'830' decimal 2096 this what is in the AX register which typically is where the return code is
It seems obvious to me that the first under score is about 150 characters away ( I didn't do a exact count ) but it is in that range
Anyway if someone could explain I would apprecaite it
|
|
|
|
|
Howdy again, I just cut and past the asm listing into notepad++ to find the location of the first "_ " - in my case it was character 2258 - 0x8D2.
Don't know where the extra 162 extra bytes come from, though they seem likely to be unimportant to the discussion at this point.
Hey, what sort of machine is that ASM for? I'm curious, not recognizing the opcodes as belonging to any of the variants I've coded for.
|
|
|
|
|
MainFrame Assembler as I said I am MainFrame Assembler programmer
So if the the first "_ " is 2258 from the Richeditctrl
then the following code should color the line with the STM red
CHARFORMAT cfm;
long n = FindText(FR_DOWN|FR_MATCHCASE | FR_WHOLEWORD, &ft);
long l = LineLength(n);
SetSel(n,l);
cfm.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
SetDefaultCharFormat(cfm);
|
|
|
|
|
Indeed. I was actually thinking more along the lines of what sort of mainframe? e.g US Military, CRAY, and a couple of other whose name escapes me just now. I played with DEC Alphas a million years ago, MIPS before the orig PlayStation implemented it, Had a couple of old SuperSparc's sitting in cases in the CS building in uni. Perhaps I was simply too inarticulate. No matter. Sorry for my intrusiveness.
Yeah, one would certainly think that your code would colour the line red - though I've been spectacularly unsuccessful at changing the text colour using MFC. I can make the line bold, underlined or whatever - but I can't color the text. The same task I have easily achieved in native code in the past and cant see any special colour handling functions that seem relevant. I'm more than a little perplexed just now. Here's the (hacked together)code I have for Bolding the target line.
Also, for some reason I had to remove the other flags you'd used in FindText. It wouldn't return a valid hit for the text "_ " unless I did so, too tired to read help docs just at the moment, no doubt such limitations are mentioned in there somewhere.
Of course, if you change the "or equals" to "xor equals" you can toggle the state, rather than just setting it.
Oops! I mean, if you xor the dwEffects with CF_BOLD, instead of setting it - you'll toggle the state of the char formatting.
Also, you should be using SetSelectionCharFormat, SetDefaultCharFormat acts on the whole control, not just the selection.
void CmfcRichEditDlg::OnBnClickedButton3()
{
FINDTEXTEX ft;
CHARFORMAT cfm;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = "_ ";
long n = m_RichEdit.FindText(FR_DOWN, &ft);
long l = m_RichEdit.LineLength(n);
m_RichEdit.SetSel(n,l);
m_RichEdit.GetSelectionCharFormat(cfm);
cfm.dwMask |= CFM_BOLD;
cfm.dwEffects = CFE_BOLD;
m_RichEdit.SetSelectionCharFormat(cfm);
}
modified 6-May-12 16:32pm.
|
|
|
|
|
Thought I'd add another reply so that you get a notification.
Just solved the question of why no colouring?
I tried it as a release-mode app and voila! Tried again as a debug, Nada!
Anyways, here's a function that will flip the line back and forth between
std-weight black text & bold red text.
void CmfcRichEditDlg::OnBnClickedButton3()
{
FINDTEXTEX ft;
CHARFORMAT cfm;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = "_ ";
long n = m_RichEdit.FindText(FR_DOWN, &ft);
long l = m_RichEdit.LineLength(n);
m_RichEdit.SetSel(n,l);
m_RichEdit.GetSelectionCharFormat(cfm);
cfm.cbSize = sizeof(cfm);
cfm.dwMask = CFM_BOLD;
cfm.dwEffects ^= CFE_BOLD;
m_RichEdit.SetSelectionCharFormat(cfm);
cfm.cbSize = sizeof(cfm);
if (cfm.crTextColor == RGB(0,0,0))
cfm.crTextColor = RGB(200,0,0);
else
cfm.crTextColor = RGB(0,0,0);
cfm.dwMask = CFM_COLOR;
cfm.dwEffects = NULL;
m_RichEdit.SetSelectionCharFormat(cfm);
}
|
|
|
|
|
thnaks
tried one minor modification
after
long l = m_RichEdit.LineLength(n);
l = l + n;
|
|
|
|
|
Hi,
I have a text file that at certain lines I insert a "_" as the first character
Here is a example
_ 000000 90EC D00C 0000C 34 STM R14,R12,12(R13)
This works fine ..
I would like to highlight the first such line in Bold Red to do this i use the FindText function however for some reason this return a -1
CHARFORMAT cfm;
SetSel(0,-1);
cfm.cbSize = sizeof(CHARFORMAT);
cfm.dwMask = CFM_FACE | CFM_SIZE | CFM_BOLD |
CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED;
cfm.dwEffects = 0;
cfm.yHeight = 240;
::lstrcpy(cfm.szFaceName, "Times New Roman");
SetDefaultCharFormat(cfm);
// LOOK for the first executable instruction
SetSel(0,0); // start at the beginig
FINDTEXTEX ft;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = (LPSTR) "_ ";
long n = FindText(FR_MATCHCASE|FR_WHOLEWORD, &ft);
long l = LineLength(n);
SetSel(n,l);
cfm.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
SetDefaultCharFormat(cfm);
SetSel(0,0);
|
|
|
|
|
It's a very simple fix. I must have spent 1/2 an hour looking over it until it hit me - you're missing a flag from the call to FindText.
long n = FindText(FR_MATCHCASE|FR_WHOLEWORD, &ft);
long n = FindText(FR_DOWN | FR_MATCHCASE|FR_WHOLEWORD, &ft);
|
|
|
|
|
Thanks worked howeever the return code from FindText was a big number X'00000830'
This is what I observed in the AX register which is always the return code from a API
I thought the return code would be the zero based character which is alot smaller
if you have any clues Please Let me know
I am going to Start another thread reagarding this question as may be I am
misunderstanding the concept
thanks
|
|
|
|
|
That's okay.
It's a bit hard to tell without seeing the data that you've got in the control. From your number X'00000830', I don't know if you mean 830 or 0x830.
In either case, it's indicating that the (0x?)830th character is the start of the sequence you're searching for.
Assuming (say) 20 chars per line & 830 decimal, this would correspond to the 10th char of the 42nd line in the control.
|
|
|
|
|
Hello,
I am working on a math program for my daughter in C# using a Form. Here is the gist of my program:
1) Create random numbers.
2) Add numbers together. Compare to user input.
3) Tell user if question was answered correctly.
I can get the program to cycle through once successfully. I can't figure out how to loop through a series of 50 questions though. When I've tried to loop it, I either end up on question 50 or suffer through an infinite loop.
If anyone could point me in the right direction, I would greatly appreciate it. Also, this is the first time I've posted in a programming forum so I've left out any pertinent info please let me know!!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Math
{
public partial class NewMathForm : Form
{
public NewMathForm()
{
InitializeComponent();
int questionCounter = 1;
addition();
}
private void sumTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
sumTextBox.SelectionStart = 0;
}
public void shuffle(ref int[] array)
{
Random rng = new Random();
int count = array.Length;
while (count > 1)
{
int k = rng.Next(count);
count--;
int temp = array[count];
array[count] = array[k];
array[k] = temp;
}
}
private void parseNumbers(ref int[] array)
{
double addend1 = 0;
double addend2 = 0;
string number;
char num1;
char num2;
for (int count = 0; count < 50; count++)
{
number = array[count].ToString();
num1 = number[0];
int length = number.Length;
if (length < 2)
{
char zero = '0';
num2 = zero;
}
else
num2 = number[1];
addend1 = System.Char.GetNumericValue(num1);
addend2 = System.Char.GetNumericValue(num2);
array[count] = Convert.ToInt32(addend1);
count++;
array[count] = Convert.ToInt32(addend2);
}
}
private void addition()
{
int[] numbers = new int[100];
int counter = 0;
int questionCounter = 1;
int numberOfQuestions = 50;
for (counter = 0; counter < 100; counter++)
{
numbers[counter] = counter;
}
shuffle(ref numbers);
parseNumbers(ref numbers);
addendOneLabel.Text = numbers[questionCounter].ToString();
addendTwoLabel.Text = numbers[questionCounter + 1].ToString();
}
private void checkAnswerButton_Click(object sender, EventArgs e)
{
checkAnswer();
}
public void checkAnswer()
{
int sum = Convert.ToInt32(sumTextBox.Text);
int number1 = Convert.ToInt32(addendOneLabel.Text);
int number2 = Convert.ToInt32(addendTwoLabel.Text);
int answer = number1 + number2;
if (answer == sum)
correctAnswer();
else
incorrectAnswer(answer);
}
private void correctAnswer ()
{
MessageBox.Show ("That is correct!");
}
private void incorrectAnswer (int sum)
{
MessageBox.Show ("That is incorrect! The correct answer is " + sum + ".");
}
}
}
|
|
|
|
|