Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
BenoitRen

I want to make a Notepad alternative in C

Recommended Posts

I've followed this tutorial on the Windows API, and would like to make a simple Notepad alternative, using the RTF control, in C. I have Borland C++ 4.52 installed, and downloaded a Win32 API Reference from Borland.

The problem is that I haven't been able to find out how to load a DLL and use its functions. Anyone know where I might find a guide to it?

Thanks in advance.

Share this post


Link to post
Share on other sites

Basically there are 2 ways. You can let the linker do it, or you can do it yourself. To let the linker do it you'll have to link your program with a .lib file. In most cases the lib file has the same name as the dll. You'll have to link shell32.lib to use shell32.dll functions. Somewhere in your project settings you should be able to specify which libs to link.

The other way it to use LoadLibrary() to load a dll, and GetProcAddress() to import a function.

The downside of letting the linker do it is that your program will not load if the dll or one of the functions you need don't exist. (Unless you're using 'delayloaded dll's'), and that the dll is loaded when your executable loads, causing extra startup time, even when you probably don't need the function.

The downside of importing by hand is that it can be a lot of work, and is error prone. (It's easy to use the wrong prototyping, since the function is just a pointer.)

Share this post


Link to post
Share on other sites

I'll need the DLL throughout the entire program, so I think it's best to use implicit linking. Yeah, I've read that you can use a .lib, but also that you can use a header file to expose the necessary functions.

My Borland C++ is old, though, and doesn't have libraries for riched32.dll or riched20.dll :( The Internet doesn't seem to have it, either.

Share this post


Link to post
Share on other sites
I've read that you can use a .lib, but also that you can use a header file to expose the necessary functions.

You have to do both. The header is nessesary for the compiler to know the function names and prototyping, the .lib is for the linker to create the import table. A headerfile *can* contain some pragma to tell the linker which library to load.

My Borland C++ is old, though, and doesn't have libraries for riched32.dll or riched20.dll The Internet doesn't seem to have it, either.

You'll need the 'Microsoft Platform SDK' to get all header and library files. Unfortunately this is a 1GB+ download, and I'm afraid it will not be compatible with your compiler/linker. The oldest version which is still served by MS where I'm aware of is found here. 'Only' 340 MB. This version is compatible with VC++6.0, all later versions aren't. Maybe it's compatible with your tools.

Do you know that Borland has a new generation of free development tools? They're Back. I don't know if these run on W98.

Update: Some Googling took me to this site, which looks like the '98 PSDK. Maybe you've enough with iBLDENV.exe (build environment).

Edited by Mijzelf

Share this post


Link to post
Share on other sites

Thanks. There doesn't seem to be a Rich Edit Control library in iBLDENV, though. I looked in iCOM and iOTHER too, but they don't have any either.

Share this post


Link to post
Share on other sites

According to Microsoft you can create a Rich Edit Control via CreateWindowEx. Then you have a window handle to send messages to. No need for function importing.

Share this post


Link to post
Share on other sites

I got the code right, but the RichEdit control creation is failing. I really need that library and header file...

I would download the entire SDK if I had to, but my brother has been downloading way too much porn and watched too many YouTube movies, so our connection is capped.

Share this post


Link to post
Share on other sites
I got the code right, but the RichEdit control creation is failing. I really need that library and header file...

The declarations are inside RichEdit.h, which you have. It's inside iBLDENV.Exe\WIN32-B.cab. This cab contains libraries too, but no RichEdit.lib. The header doesn't define any functions, so I suppose there isn't any library.

The creations fails. You mean CreateWindowEx returns 0? What does GetLastError() return?

I would download the entire SDK if I had to, but my brother has been downloading way too much porn and watched too many YouTube movies, so our connection is capped.

Yeah. Belgium is famous for it's generous download limits.

Share this post


Link to post
Share on other sites

I must not have looked well enough, because I even have a Richedit.h in my Borland installation, which is 1/3 the size of the one in the SDK.

Indeed, CreateWindowEx returns 0. So does GetLastError(), even after using the header files. I tried with both versions I got.

Here's the relevant code:

	hRichEdit = CreateWindowEx(0, "RichEdit", "",
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE,
0, 0, 200, 100,
hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);

ltoa(GetLastError(), errStr, 10);

if(hRichEdit == NULL) {
MessageBox(NULL, errStr, "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}

Belgium is famous for it's generous download limits.

Really? Someone I know from the Netherlands didn't know until I talked about it recently.

I wouldn't mind the limit if it wasn't for my brother's download habits. There's enough for the rest of the household.

Edited by BenoitRen

Share this post


Link to post
Share on other sites

hRichEdit = CreateWindowEx([b]WS_EX_CLIENTEDGE[/b], "RichEdit", "",
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE,
0, 0, 200, 100,
hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);

Also I think you need to either LoadLibrary(...) or do InitControl() before the RichEdit control is/can be created.

Man it's been years since I played with v4.52, I'm using MSVS2005 Pro now

MSVS 2005/2008 Express Edition is free from MS btw ... Just a Thought ;)

Edited by Stoic Joker

Share this post


Link to post
Share on other sites
Also I think you need to either LoadLibrary(...) or do InitControl() before the RichEdit control is/can be created.

Microsoft says you should call LoadLibrary() to determine which version of RichEdit is available. A side effect could be that the dll is loaded and the class registered.

I suppose you mean InitCommonControls()?

hRichEdit = CreateWindowEx( 0, "RichEdit", "",
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE,
0, 0, 200, 100,
hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);

I don't think an edit control can have a menu. It should be in the parent frame. I would expect an error though.

MSVS 2005/2008 Express Edition is free from MS btw ... Just a Thought
Using Windows 95 OSR 2.5

That doesn't mix.

Share this post


Link to post
Share on other sites
I suppose you mean InitCommonControls()?

Right! ...It's been a while since I played with richedit controls, but I recall there being a simple way to load them, I just can't seem to find it in my old notes. I mainly do system utilities these days.

MSVS 2005/2008 Express Edition is free from MS btw ... Just a Thought
Using Windows 95 OSR 2.5

That doesn't mix.

Zoiks! (missed that) I was thinking the target machine was 9x, not the developement machine.

Share this post


Link to post
Share on other sites

Using InitCommonControls() generated an error that the function was not known. LoadLibrary("riched32.dll"); worked, though!

Thank you very much, both of you. :)

Share this post


Link to post
Share on other sites

FYI: When you Google on a Win32 function, InitCommonControls() in this case, you'll find a hit in msdn2.microsoft.com. On this page you often can find which header and import library you need, commctrl.h and comctl32.lib in this case. So you should have included commctrl.h, making the compiler happy. Next to complain would have been the linker, which cannot resolve this function, so you should have linked comctl32.lib.

However, it seems to be not nessesary here. That's according to the documentation which says you'll only need InitCommonControls() when you want to use XP theme's in your rich edit. But on the other hand, it stated you'll only need to call LoadLibrary() to find out which version of rich edit you have, which seems to be untrue.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...