|
Kant wrote:
1. How to build a DLL in C#? The options I got are "Windows Application, ASP.NET Web Service, ASP.NET Web Application and Console Application"
Duah...I got standard version of C#.
Visual C# Standard Edition Features[^]
Kant wrote:
2. What's the equivalent of friend (C++) in C#?
Got it from here.[^]
Don't and drive.
|
|
|
|
|
Hi Kant,
Welcome to the C# from C++ boat!
I don't know the answer to the first question, but I'm pretty confident I can answer the second one.
The answer is: there isn't an equivalent.
The best way to work around it is qualifying those members which you want to make accessible as internal . This basically makes them public to any classes within the same assembly.
Regards,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
HISTORY: I'm trying to get the javascript in a page to execute a method in my FAT client. I implemented the DLL from the article here on implementing IDocHostUIHandler. I implemented my own interface. I know IDocHostUIHandler is properly hooked because I am stopping the context menues from displaying.
I was given a quick hint to look at window.getexternal so that window.external does not error with a null object error. BUT now I am getting a null object on window.getexternal. AAAArrrrggghhh. So can anyone tell me where I'm screwing up???? Here are my code pieces:
my html test:
<br />
<HTML><br />
<HEAD><br />
<Title> Test of hooking into IDocHostUIHandler </Title><br />
<script language="JavaScript" id="clientEventHandlersJS"><br />
<!--<br />
function callHostUI(sectionName)<br />
{<br />
window.getexternal.ClickEventHandler();<br />
window.external.ClickEventHandler(sectionName);<br />
}<br />
--><br />
</script><br />
</HEAD><br />
<body><br />
<INPUT id="btnExit" onclick='callHostUI("The test finally worked")' style="Z-INDEX: 102; LEFT: 15px; <br />
WIDTH: 108px; COLOR: white; BORDER-TOP-STYLE: none; FONT-STYLE: normal; <br />
FONT-FAMILY: 'Book Antiqua'; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: <br />
none; POSITION: absolute; TOP: 227px; HEIGHT: 40px; BACKGROUND-COLOR: navy; <br />
BORDER-BOTTOM-STYLE: none" type="button" value="Test GetExternal"><br />
</body><br />
</HTML><br />
my interface implementation:
<br />
interface IPageClickHandler<br />
{<br />
void ClickEventHandler(string SectionName);<br />
}<br />
<br />
namespace myProgramNamespace<br />
{<br />
public class pageEditor : System.Windows.Forms.Form, IPageClickHandler, IDocHostUIHandler<br />
my IDocHostUIHandler implementation:
<br />
InitializeComponent();<br />
holdPageName = pageName;<br />
object flags = 0;<br />
object targetFrame = String.Empty;<br />
object postData = String.Empty;<br />
object headers = String.Empty;<br />
this.showWebPage.Navigate("about:blank", ref flags, ref targetFrame, ref postData, ref headers);<br />
ICustomDoc cDoc = (ICustomDoc)this.showWebPage.Document;<br />
cDoc.SetUIHandler((IDocHostUIHandler)this);<br />
this.showWebPage.Navigate(@"D:\TestHTMLData\TestConversation.html", ref flags, ref targetFrame, ref postData, ref headers);<br />
and my getexternal implementation
<br />
void IDocHostUIHandler.GetExternal([MarshalAs(UnmanagedType.IDispatch)] out object ppDispatch)<br />
{<br />
ppDispatch= (IPageClickHandler)this;<br />
throw new COMException("", S_OK);<br />
}<br />
No matter what I try, I keep getting window.getexternal is a null object! If I try window.GetExternal I get an error that the method does not exist, so my method call must be somewhat correct. I've tried the call as
window.getexternal.mymethod()
and I tried it as
window.getexternal.myinterface()
both return a null object error.
So what the heck am I doing wrong????? I cannot figure it out!
Thanks for ANY help,
MJ
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
theRealCondor wrote:
window.getexternal.mymethod()
window.getexternal.myinterface()
...
I see nothing wrong in the fact it does not work. Indeed, window.getexternal does not even exist in the javascript object model. You've got to stick with window.external. If you intend to add callable methods, then they'll be called like this : window.external.mymethod(...)
theRealCondor wrote:
I know IDocHostUIHandler is properly hooked because I am stopping the context menues from displaying.
Not sure. You are passing something thanks to the .SetUIHandler(...) method call, but may be you are passing null, an abstract interface, a class which doesn't implement idispatch methods, or even a class with a wrong layout.
The IDocHostUIHandler technique using C# must be paid special attention. That's why, again, the reference article on Cp should be your starting point. Additionally, here[^] are useful entry points.
|
|
|
|
|
.S.Rod. wrote:
That's why, again, the reference article on Cp should be your starting point.
Well -- AGAIN I did start with all of the articles here on CP. I also followed several discussion threads. Nowhere on this site has anyone posted anything that does this in a full working discussion. All of the discussions go up to a point, a promise to post a sample project, then NOTHING. A dead discussion. And it was a post here on CP that said to look at doing GetExternal, and it was here that it looked like he was suggesting I do a window.getexternal.
I implemented IDocHostUIHandler following the article that was written by Nikhil Dabas and I deployee the MsHstHtmInterop.Dll component from his article. And, as shown in my code I included in my post, when I
<br />
throw new ComException("", S_False);<br />
I see the context menues. And when I
<br />
throw new ComException("", S_OK);<br />
I do not see the context menues.
Now having said that, executing JUST window.external produces these lustrous results:
'window.external' is null or not an object
I have also searched HUNDREDS of results form Google. Lots of talk about simple hooks and hundreds of posts about stopping the context menu. NOTHING is there about having javascript hit a method in my WinForm.
Now if you have any helpful comments that I can actually act on, I'd be greatful to hear them.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
theRealCondor wrote:
I have also searched HUNDREDS of results form Google. Lots of talk about simple hooks and hundreds of posts about stopping the context menu. NOTHING is there about having javascript hit a method in my WinForm.
It's useless to search hundreds of posts if you don't know what you are looking for.
Here is how it works :
- anyone willing to implement custom menus or external method calls should register a custom site handler. That's what is done with the ICustomDoc.SetUIHandler(object) method call.
- the passed object reference has to implement the IDocHostUIHandler interface, an IUnknown based interface. Among the methods are one which is used as an entry point for all window.external.mymethod() calls, that's GetExternal(out object ppDispatch) .
- the GetExternal method should return a reference to an object which implements a dispatch interface. In case you don't know, a dispatch interface is a standard automation interface providing the ability to have methods called by their names, thanks to two helper methods : GetIdOfName() and Invoke() .
- the good news is that the .NET CLR provides helper attribute, namely [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)], which implements all the underlying plumbing. What's left to do is to declare and implement the actual methods.
- in the end, we have a sample html file, which reacts on clicks by calling javascript's window.external.MyMethod() . In order for this to work, the afore mentioned object must declare and implement the MyMethod() method.
Here is how to declare the IDispatch interface :
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMyInterface
{
void MyMethod();
}
Here is how to implement it :
public class IMyInterfaceImpl : IMyInterface
{
public void MyMethod()
{
MessageBox.Show("my method");
}
}
Here is how to attach this interface to IDocHostUIHandler :
void IDocHostUIHandler.GetExternal(out object ppDispatch)
{
ppDispatch = new IMyInterfaceImpl();
}
Finally, here is a sample html code for a demo :
<html>
<body>
<script language="javascript">
function myclick()
{
window.external.MyMethod();
}
</script>
<p>Nothing in particular here.</p>
<a href="javascript:myclick()">click</a>
</body>
</html>
|
|
|
|
|
Thank you very much. With a clear description of what was going on, I got the implementation straightened out....and it works. So my implementation of IDocHostUIHandler seems to be fine -- it was just how I was told to implement the method to be executed.
You have ended a horrendous two-week hunt through a large number of articles and websites.
Thank you VERY much.
MJ
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
theRealCondor wrote:
You have ended a horrendous two-week hunt through a large number of articles and websites
<sadistical>It took me a couple of minutes to bring the implementation up (from that now famous starting point article in CodeProject)</sadistical>
[edit]Glad it works now, especially if you were doing real work. May be it's good to either post an article (only to remember those two passionate weeks from start to end, could be interesting discovery perspective), or add a comment in Niki's article.[/edit]
|
|
|
|
|
Actually, I am beginning to put together an article as well as a sample application. I have had no raw COM development experience -- this was the first time for me. So it has taken me longer to understand all this stuff.
Now here is one more question to you!
I have a need for the exposed method to populate a property sheet in my fat client. Much more complex than a stand-alone class that throws a message box. I built the sample app to do this:
It has rows of buttons corresponding to product pictures.
Click on the button and it calls my client. The client populates the form.
The example is a fun, twinky deployment to test my more difficult property object setting.
So instead of defining a separate class implementation of my interface
ppDispatch = new ClassInstance();
I am doing an implementation in my code.
ppDispatch = this;
So I have my interface:
<br />
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]<br />
public interface IPopulateWindow<br />
{<br />
void PopulateWindow(string item);<br />
}<br />
and I'm setting ICustomDoc.SetUIHandler in my constructor logic and inside my code I have the interface implemented:
<br />
void IPopulateWindow.PopulateWindow(string itemSelected)<br />
{<br />
switch (itemSelected)<br />
{<br />
<snip> populate form based on value of selected item </snip><br />
}<br />
this.Invalidate();<br />
throw new COMException("", 0);<br />
}<br />
Now --- I am getting the window.external object populated. That is good.
But --- IDispatch is not exposing the PopulateWindow method.
(Object does not support this property or method)
Is there something else I have to implement in my form class to have IDispatch properly see my method? Do I have to mark my implemenation as
[ComVisible(true)]
for instance?
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Ach, never mind.
I finally got it working by continueing with the object as a unique class and passed reference to the form via contructor logic. That worked. So....
I have the interface definition in my namespace.
I have my implementation defined in my namespace with its' own constructor logic. I save a reference to my namespace.form object. Then when I take control of the UI, I pass the object along with a pointer at my form.
Works great!!!
Look for the sample app soon.....and I will make sure of noting your assistance in this work as well!!!
Later,
Michael
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
I used this piece of code to gain binary representation of a
float number...
byte* p;
float f = 11.0F;
p = (byte*)(&f);
Console.WriteLine("First Byte: " + *p++);
Console.WriteLine("Second Byte: " + *p++);
Console.WriteLine("Third Byte: " + *p++);
Console.WriteLine("Fourth Byte: " + *p);
But as you know we can't use pointers for managed types. Does anyone know
a method to find the binary representation of objects?
|
|
|
|
|
Here are two ways to do it :
float f = 1.0F;
byte[] buffer = BitConverter.GetBytes(f);
int nSize = buffer.Length;
byte b = 0;
for (int i=0; i<nSize; i++)
b = buffer[i];
float f = 1.0F;
IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(f));
Marshal.StructureToPtr(f, p, false);
|
|
|
|
|
Yesterday, I was trying to create a shell extension for adding items to the context menu inside windows explorer. The .NET SDK comes with a sample application for this, shellcmd, but when I use this extension and right-click on an explorer item (in this case Folder items), every program that's running will be frozen. Anyone has an idea why this is?
|
|
|
|
|
Works fine for me (W2K SP2 IE6SP1 .NET1.1+1.0SP2).
|
|
|
|
|
I'm running WXP SP1 with Visual Studio 2003 (.NET 1.1) ... VERY weird
I've just reinstalled windows this week and this is the only strange thing I encountered up until now...
|
|
|
|
|
[edit]I'm trying to use the Property grid control at runtime.[/edit]
I added the Proeprty Grid to a form, and now trying to figure out how to get the properties of an object instance into it.
Seems like
a) I have to tag the editable properties with "Browsable" (did that)
b) Get the "Browsable Proeprties" colleciton from the instance - how?
c) set it to the BrowsabeProperties prop of the property grid
Any idea?
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
Create a user control. Add properties into it. By default they become browsable. ([Browsable] is more to tell the framework to mark it as non browsable).
Need a sample? Look at the multi-selection treeview[^], where I have a public property : SelectedNodes, which is a collection. Once added to the toolbox, and dropped onto a form, you'll see that, by opening the "Properties Window", you have a SelectedNodes property under the Misc category. That's it!
|
|
|
|
|
Maybe a little misunderstanding:
I'm using the Property Grid in my application (i.e. at run time).I have a custom (dereived-from-nothing) class with application settings I want to allow my end users to adjust.
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
Hi
i'm trying to create a structure in C# that look something like this
struct TEST
{
byte t[100];
};
As i come to learn this is nothing that is supported in C#. I have tried a bunch of diffrent approaches in (using unsafe, Managed C++ etc. ) without any success.
What i want to be able to accomplish is something simmilar to this c++ snippet.
struct TEST
{
char t[100];
};
int* i=new int[100];
TEST* p=(TEST*)i;
Any suggestions appriciated
Thanks
Mikael
|
|
|
|
|
Mikaelr wrote:
As i come to learn this is nothing that is supported in C#. I have tried a bunch of diffrent approaches in (using unsafe, Managed C++ etc. ) without any success.
Amazing statement.
(C world)
byte t[100];
(C# world)
byte[] t = new byte[100];
|
|
|
|
|
Yes i know this but i'm NOT looking for creating a reference to an byte array.Which i thought it was obvious in my mail.
I want to create a fixed size array that the compiler maps to offset in the structure. So that I can cast diffrent structs on a buffer and access the data accordingly.
I have not managed to do this in C# as doing "int k[100]" is illegal.
|
|
|
|
|
Mikaelr wrote:
I want to create a fixed size array that the compiler maps to offset in the structure
Ok. I recommend to build an array of object, instead of a specialized array :
object[] m_objecttable; // declaration
m_objecttable = new int[100]; // creation of an int array
m_objecttable = new String[100]; // creation of a string array
And then use reflection to get the type at run-time,
Type objectype = System.GetType( m_objecttable[0] );
Mikaelr wrote:
So that I can cast diffrent structs on a buffer and access the data accordingly
C terminology.
|
|
|
|
|
I'm using System.Uri and System.UriBuilder with .NET Framework 1.0 SP3. It seems to be the case that the "escape string" functionality doesn't work as I'd expect a normal Uri class to work -- it doesn't escape special characters such as ' ' or '"' at all, and I don't see a way to do that in the system classes. Anyone?
Also, I just noticed that System.Uri.ToString() and System.Uri.AbsoluteUri produce different output, which is something I didn't expect.
|
|
|
|
|
Arun Bhalla wrote:
it doesn't escape special characters such as ' ' or '"' at all, and I don't see a way to do that in the system classes
They are escaped! How it works is as follows : for these characters to be escaped they must be such that IsExcludedCharacter() below returns true. Ascii code for space is 32, and ascii code for the quote is 34. Which is ok.
internal static string System.Uri.EscapeString(string rawString,
bool reEncode, ref bool escaped) {
...
do {
...
if (Uri.IsExcludedCharacter(rawString.get_Chars(local6))) {
local1 = Uri.HexEscape_NoCheck(rawString.get_Chars(local6));
break;
}
...
local6++;
} while (local6 < rawString.Length);
...
}
protected static bool System.UriIsExcludedCharacter(char character) {
if (character > 32 && character < 127)
if (character != 60 && character != 62 && character != 35 &&
character != 37 && character != 34 && character != 123 &&
character != 125 && character != 124 && character != 92 &&
character != 94 && character != 91 && character != 93)
return character == 96;
return 1;
}
A few hints :
- make sure to double quotes, instead of doing \"
- all non-ending spaces are escaped. Ending spaces are not escaped, just trim them before you pass the string to be encoded.
Arun Bhalla wrote:
Also, I just noticed that System.Uri.ToString() and System.Uri.AbsoluteUri produce different output, which is something I didn't expect
Different implementations indeed.
|
|
|
|
|
How I can add a tooltip text with explanation in my code - so when I try to call some function/propertie the tooltip automaticly generated by C# will be with my text ? For example - when you type somthing like this:
String.CompareTo (
Tooltip at the bottom will show the return type and a little info about this function. How I can make something like this in my program ?
|
|
|
|