|
VB.NET and C# projects will go fine. The only trouble will be with C++ projects, because there were some language changes, but not a big deal.
My latest article: GBVB - Converting VB.NET code to C#
|
|
|
|
|
We know the default TCP/IP port of SQL Server 2000 is 1433.
I can connect to DB from remote using SQLConnection class. But when the default port is changed, I couldn't.
How can I connect to DB with different TCP/IP port?
|
|
|
|
|
Hi mkomasi,
I have'nt tried much on SQL Server. Although, you may like to try http://www.connectionstrings.com/[^] for a variant of ConnectionString that can faciliate connecting to a different port. Alternatively, does OLEDB allow that? A suitable connectionstring should help you there too? Try that URL.
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
The content of the textbox is a pathname.
I want to change the path and then press
"save as default" -> now the default path
should be the new one (even after restarting)
Is this possible?
thanks and regards
markus
|
|
|
|
|
Yes, search on "Dynamic Properties", you can bound the Text property of your TextBox to a config file.
Hope this helps.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
yes that seems to work
but when i try to save the new path i get an exception:
"Collection is Read Only"
my code:
private void button1_Click(object sender, System.EventArgs e)
{
Configuration.ConfigurationSettings.AppSettings.Set
("textBox1.Text", newPath);
}
thanks and best regards
|
|
|
|
|
Hi all...I'm writing a small program (learning C#....yes I'm a beginner). I am using the RichTextBox control that the users can enter or paste in some text. Then afterward, I want to go through that text in the control character by character and be able to determine each characters font style, size, etc.....
Can anyone point me in the right direction for that? I was able to set fonts, etc... correctly (giving them a context menu to do a few things), when its all said and done I want to parse the style, character by character.
Help Please! Small example, or web page example, or even a pointer as to what methods to start with would be helpful.
Thanks.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
For finer control over richtext, you can serialize the contents to a file or string and then parse it individually using the RT file format, you can get the format from wotsit[^]
- Kannan
|
|
|
|
|
I have a weblog thing I made in C#, ASP.NET, it works fine and everthing and stores each entry into and .xml file. Now usually I edit and make new entrys though internet explorer, but then I though how cool would it be to make an application in C# to take the .xml file edit it in the program, then click the save button and have it update the .xml!
Does anybody have any tips or places to look, for help on this???
/\ |_ E X E GG
|
|
|
|
|
|
Thanks for the effort, but that's not what I really wanted... dont' worry about it....
/\ |_ E X E GG
|
|
|
|
|
...
Prepare for confusion, but please help.
I have a plugin framework, using reflection.
This works brilliantly and I will release the code eventually. However, one of the plugins is calling an async callback. This throws an invokation exception:
Cannot load type GoogleSearch.GoogleSearchForm, GoogleSearch, Version=1.0.1212.26393, Culture=neutral,<br> PublicKeyToken=null. at System.Runtime.Remoting.Messaging.MethodCall.ResolveMethod(Boolean bThrowIfNotResolved)
at System.Runtime.Remoting.Messaging.MethodCall.ResolveMethod()
at System.Runtime.Remoting.Messaging.MethodCall..ctor(IMessage msg, Boolean needAccessCheck)
at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem..ctor(IMethodCallMessage message, AsyncResult ar, Object target)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
at GoogleSearch.SearchDelegate.BeginInvoke(String url, String& result, AsyncCallback callback, Object object)
at GoogleSearch.GoogleSearchForm.search_Click(Object sender, EventArgs e) <br>in c:\documents and settings\administrator.jonny\my documents\visual studio projects\screenmate\googlesearch\google.cs:line 219
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods<br>+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at GoogleSearch.GooglePlugin.LoadGoogleForm()<br> in c:\documents and settings\administrator.jonny\my documents\visual studio projects\screenmate\googlesearch\google.cs:line 36
Now, let me tell you how the app works. The main app gets methods via reflection. And in the end get to this point:
object o = Activator.CreateInstance(t);
MethodInfo mi2 = t.GetMethod("AcceptRect");
Rectangle rect = new Rectangle(this.Location,this.Size);
mi2.Invoke(o,new object[]{rect});
Now that works fine on all plugins, including the troublesome one.
Now in the plugin class, there is a call to another class in the plugin dll. One based on a windows form. The form loads ok.
A button on the form starts an async callback to process some data. NOW THIS DOESN'T WORK.
GoogleSearch.GoogleSearchForm gs = new GoogleSearch.GoogleSearchForm(this.bob);
gs.ShowDialog();
The above opens the form. (This is all within the same dll and namespace)
SearchDelegate search = new SearchDelegate(this.Search);
string result;
search.BeginInvoke(url, out result, new AsyncCallback(this.AnnounceSearch),search);
public delegate string SearchDelegate(string url, out string result);
public string Search(string url, out string result)
{
ArrayList ar = new ArrayList();
Uri uri = new Uri(url);
WebRequest wr = WebRequest.Create(uri);
WebResponse resp = wr.GetResponse();
Stream s = resp.GetResponseStream();
StreamReader sr = new StreamReader(s);
string t = sr.ReadToEnd();
sr.Close();
return (result = t);
}
public void AnnounceSearch(IAsyncResult iar)
{
SearchDelegate search = (SearchDelegate)iar.AsyncState;
string result;
search.EndInvoke(out result, iar);
this.panel1.Controls.Clear();
MakeControlsDelegate del = new MakeControlsDelegate(MakeControls);
this.Invoke(del,new object[]{result});
}
public delegate void MakeControlsDelegate(string t);
public void MakeControls(string t)
{
ArrayList gr = this.ParseGoogle(t);
foreach(LinkLabel ll in gr)
{
this.panel1.Controls.Add(ll);
}
Ok, I think thats everything now...
Anyway, the above code WORKED PERFECTLY when it was not a plugin and was just a compile time dll.
The only thing i've changed is the fact that the form is being run from a late-binding dll.
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "If a man is standing in the middle of the forest speaking and there is no woman around to hear him, is he still wrong?" - Anon
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
You are likely having a threading issue. Try as the AsyncCallback is invoked from another thread. Do the following:
from your control:
Invoke(mi.Invoke, new object[]{o, new object[]{rect}});
Eek. Dunno if that will work, but give it a try
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
I'm not sure I understand where i'm to place that.
The plugin is activated and invoked from a form in the main app and main thread.
From the new instance of the plugin, the plugin class loads the plugin form.
object o = Activator.CreateInstance(t);
MethodInfo mi = t.GetMethod("SomeMethod");
mi.Invoke(o,null);
does the above code create the instance of the object in a new thread, or the same thread as the method that runs it?
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "If a man is standing in the middle of the forest speaking and there is no woman around to hear him, is he still wrong?" - Anon
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
Jonny Newman wrote:
does the above code create the instance of the object in a new thread, or the same thread as the method that runs it?
That will create the object in the calling thread.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Jonny Newman wrote:
Anyway, the above code WORKED PERFECTLY when it was not a plugin and was just a compile time dll.
The only thing i've changed is the fact that the form is being run from a late-binding dll.
Just judging from that I would say there is a problem with the application resolving assemblies.
In the FrameworkSDK\bin directory (located within VS.NET's install folder) you'll find FUSLOGVW.exe which will let you see what the runtime is trying to do to find the assemblies it needs to load.
Run that, make sure you check the "Log Failures" checkbox, then run your application. You should see where it is expecting to find the assemblies it is loading, and if it fails to load an assembly the plugin depends on.
HTH,
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\WINNT\Microsoft.NET\Framework\v1.0.3705\fusion.dll
Running under executable C:\Documents and Settings\Administrator.JONNY\My Documents\Visual Studio Projects\ScreenMate\ScreenMate\bin\Debug\ScreenMate.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = GoogleSearch, Version=1.0.1212.29205, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = C:\Documents and Settings\Administrator.JONNY\My Documents\Visual Studio Projects\ScreenMate\ScreenMate\bin\Debug\
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===
LOG: Processing DEVPATH.
LOG: DEVPATH is not set. Falling through to regular bind.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: GoogleSearch, Version=1.0.1212.29205, Culture=neutral, PublicKeyToken=null
LOG: Attempting download of new URL file:LOG: Attempting download of new URL file:LOG: Attempting download of new URL file:LOG: Attempting download of new URL file:LOG: All probing URLs attempted and failed.
Well, it seems to state that the dll was never loaded.
However, the dll must have been loaded because the form the button is on is in that dll, code is actually being run from it. It is definately something to do with the async callback.
Should I try starting the Activator.CreateInstance() in another thread?
Threading isn't my strong point.
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "If a man is standing in the middle of the forest speaking and there is no woman around to hear him, is he still wrong?" - Anon
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
I don't think your problem has to do with threading. It doesn't matter on which thread you are trying to create the object, the CLR cannot find the assembly file that the object is defined in.
Which files do you have as part of your application? Presumably you have an application exe and the GoogleSearch.dll is the plugin.
Is the GoogleSearch dll located at any of the locations in the output above? If so is the dll of the same version listed above (i.e. 1.0.1212.29205)?
Regards
Mark Smithson
|
|
|
|
|
googlesearch.dll is located in the /plugin directory. But I don't see how this causes a problem since the plugin is already loaded and working, so the file location shouldn't matter, but obviously if its looking in the wrong place for it then there must be a problem.
On the point of asyncs. Would it help if I made the async methods static, might this help resolve stuff?
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "If a man is standing in the middle of the forest speaking and there is no woman around to hear him, is he still wrong?" - Anon
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
I'm not really sure what you mean by 'loaded and working'. You code and the errors imply that the CLR cannot load a type.
This is because your plugin directory is not in the probing path for the application. Your will either need to change your applications config file to include this directory, or manually load the assemblies.
Try adding the following to your app.config file
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="plugins"/>
</assemblyBinding>
</runtime>
</configuration>
Also have a look at the following MSDN link for further information on the how the CLR locates assemblies
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconhowruntimelocatesassemblies.asp
Regards
Mark Smithson
|
|
|
|
|
Cheers that seems to have done the trick! I knew it would be simple
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "If a man is standing in the middle of the forest speaking and there is no woman around to hear him, is he still wrong?" - Anon
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
Hi all (and S.Rod. as you are most likely to answer this )
Say I have a C function:
char** Foo(int* size);
Now in MC++ its pie and I can just go:
int size = 0;
char** buffer = Foo(&size);
String* results __gc[] = new String*[size];
for (int i = 0; i < size; i++)
{
results[i] = new String(buffer[i]);
free(buffer[i]);
}
free(buffer);
But how do I approach this from a Marshalling POV in C# given I have Foo as a DllImport defined as IntPtr Foo(out int size) ? How do I access the individual char* and the finally free the returned IntPtr? My attempts has failed miserably
Thanks
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Here is how I got it to work,
C implementation :
extern "C" __declspec(dllexport) char** foo(int *nSize);
__declspec(dllexport) char** foo(int *nSize)
{
*nSize = 2;
::MessageBox(NULL,"unmanaged foo call","message",MB_OK);
char **lpstr = (char**) CoTaskMemAlloc( 2*sizeof(LPSTR) );
lpstr[0] = (char*) CoTaskMemAlloc( 100 ) ;
strcpy(lpstr[0], "string1");
lpstr[1] = (char*) CoTaskMemAlloc( 100 ) ;
strcpy(lpstr[1], "string2");
return lpstr;
}
Now for the managed part,
[DllImport(@"..\bin\foo.dll", CharSet=CharSet.Auto)]
static public extern IntPtr foo(ref int nSize);
int nSize = 0;
IntPtr pData = foo(ref nSize);
for (int i=0; i<nSize; i++)
{
IntPtr pString = Marshal.ReadIntPtr(pData, 4*i);
MessageBox.Show( Marshal.PtrToStringAnsi(pString) );
}
|
|
|
|
|
.S.Rod. wrote:
Marshal.ReadIntPtr
Dope, how did I miss that one again (some bells ring)? PtrToStringAnsi frees the string, would FreeHGlobal(pData) at the end be right then?
Thanks for the reply
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
|