|
Hi:
I have looked over the material I can find on programatically installing and uninstalling type fonts in windows but I must be missing some pieces to the puzzle.
Here is an example of what I seem to not be able to compile in Visual C# 2008
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/dd2e5ccc-3f6e-4c73-8bf8-565b18107a5a/[^]
and I can find no information on the AddFontResource method nor is it recognized in my namespace.
Any advice would be helpful.
|
|
|
|
|
HighCloud wrote: Here is an example of what I seem to not be able to compile in Visual C# 2008
What errors does the compiler give you?
HighCloud wrote: I can find no information on the AddFontResource method nor is it recognized in my namespace.
AddFontResource is a Windows API function that is invoked through the PInvoke call in C#. See here[^] for details.
|
|
|
|
|
Thanks for your reply.
Being somewhat of a beginner, my main problem is that I can not seem to find any using statement or reference that will recognize these functions:
AddFontResource()
SendMessage()
WriteProfileString()
The example link in my previous post shows an external declaration.
Another example that has come up from sources on the internet is a statement such as:
FontInstall.AddFontResource();
Prehaps I do not need them at all, but learn how to use the API.
Please comment.
|
|
|
|
|
Hi,
P/Invoke is the way to access existing native functions, in this case they reside in system files gdi32.dll and user32.dll; the "extern" keyword tells the C# compiler only a prototype is provided, the implementation is to be found in those DLL files.
What seems to be missing in the article is the fact that your code should start with a statement
using System.Runtime.InteropServices; for the compiler to understand what DllImport means.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Thankyou. You are right. That was a missing piece for me.
Now that you have told me about the PInvoke, I looked that up on the MSDN web site and they have a tutorial there which I will study.
a couple of questions that I have right now is:
do I copy the dll's from my system directory to my project to use them?
Is this the best way to install a type font programatically?
|
|
|
|
|
See here[^] for some good information on the AddFontResource function, and PInvoke in general.
HighCloud wrote: do I copy the dll's from my system directory to my project to use them?
No, the runtime system knows where to find them.
HighCloud wrote: Is this the best way to install a type font programatically?
I'm not sure of the answer to this one, but there are some useful articles on Fonts here on CP.
|
|
|
|
|
Thanks again.
I believe that for now I have enough information to compile and experiment with this material.
|
|
|
|
|
Hi,
could you provide the P/Invoke link? I am in the middle of writing an article on the subject, and eager to get more material.
FYI: you don't have to install a font to use it in your own app, there is a PrivateFontCollection class that could help you out. (I haven't used it myself though).
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
See my previous answer; it's PInvoke.net. Surprised that you didn't know about this, I felt sure you would have written some of it.
|
|
|
|
|
Sorry, I misunderstood. I have known and like pinvoke.net for years (even when it has some errors); I am looking more for tutorial material though.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I must admit to being somewhat surprised that you did not know about it. Unfortunately it's my only source, although some of the entries do contain some quite useful sample code.
|
|
|
|
|
As I said before, I have been using www.pinvoke.net for many years. It offers reasonable reference material, somewhat incomplete and sometimes plain wrong.
I would like to see better P/Invoke tutorial stuff e.g. explaining all the Marshaling alternatives, and that is why I am writing my own article right now.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc Pattyn wrote: and that is why I am writing my own article right now.
Excellent news; I'm looking for a decent tutorial
|
|
|
|
|
Would you be interested in proofreading and providing feedback?
I plan a two-part article, of which the first part is almost ready (except for the download).
It contains general principles and many simple examples (C# so far, will be adding VB.NET), but skips everything about structs.
BTW: not sure I will publish it on CP as the house style doesn't really fit; I'll have to take that up with Chris in a couple of weeks.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc Pattyn wrote: Would you be interested in proofreading and providing feedback?
I'd be happy to help in any way I can, although I have to warn you I'm neither a brilliant programmer nor an accomplished technical writer.
|
|
|
|
|
AddFontResource is not on PInvoke.net (yet)
|
|
|
|
|
harold aptroot wrote: AddFontResource is not on PInvoke.net (yet)
Shazzam![^]
|
|
|
|
|
Wut?
I did a search for it 4 hours ago, no results..
|
|
|
|
|
harold aptroot wrote: I did a search for it 4 hours ago, no results..
Come on Harold, this isn't like you, get a grip! What's this[^]?
|
|
|
|
|
I don't know man
It certainly looks like the right page?
How did you find it?
|
|
|
|
|
harold aptroot wrote: How did you find it?
www.pinvoke.net then use the left hand selector to find gdi32. Click the plus sign and it opens up, and you can see the individual entries.
I already new www.pinvoke.net to start with, so I did not Google it; maybe it's not well indexed.
|
|
|
|
|
Hm.. I tried to use that search bar of pinvoke itself (left top)
Apparently it doesn't work so well..
|
|
|
|
|
harold aptroot wrote: Hm.. I tried to use that search bar of pinvoke itself (left top)
Apparently it doesn't work so well..
This is weird, I just tried it and it worked fine. It found AddFontResource, AddFontResourceEx and RemoveFontResource! Even just using "fontresource" as a search key finds them all.
|
|
|
|
|
Hm.. that's not good, that means I'm becoming like CG, everything malfunctioning around me
|
|
|
|
|
harold aptroot wrote: Hm.. that's not good, that means I'm becoming like CG, everything malfunctioning around me
do
{
I have days like this when I spend hours tweaking code, testing, asserting, throwing etc. And then, after what seems a lifetime, I spot the misplaced comma, the transposed operand, or whatever, and suddenly it all starts to work correctly. But I never tell anyone else about the stupid mistake I made, that the rawest rookie could spot from twenty-five paces. I just mutter into my coffee and promise not to be so careless in future.
} while (true);
|
|
|
|