|
typeof(SomeClass).GetProperties().Length
:josh:
My WPF Blog[^]
|
|
|
|
|
Thanks Josh..........for your help...this worked.....
suneet
|
|
|
|
|
Hi all. I need to call a method of my .NET COM-object from Word. How can I do it?
I've written an object, checked all these "COMVisible", "register for COM Interop" etc.
In Word I can see a reference to it. After adding the reference I write the script:
Dim Ob As Object
Set Ob = CreateObject("ClassLibrary1.FOO")
On CreateObject line I get: "Run time error 429. ActiveX component can't create object".
Or if I write so:
Dim Ob As Object
Set Ob = New Classlibrary1.FOO
I get: "Run-time error -2147024894 (80070002). File or assembly Classlibrary1, or one of it's dependencies was not found".
Which dependencies? It's just a test project! Here is the source code:
using System;
using System.Runtime.InteropServices;
namespace Chapter_Code
{
[GuidAttribute("1C6CD700-A37B-4295-9CC9-D7392FDD425D")]
public interface IFoo
{
string PrintMe();
int ShowState();
void SetState(int newState);
}
[GuidAttribute("C09E2DD6-03EE-4fef-BB84-05D3422DD3D9")]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ProgIdAttribute("Chapter_Code.Foo")]
public class Foo : IFoo
{
public Foo() { }
private int state = 100;
public string PrintMe()
{
return ("TEST SUCCESS");
}
public int ShowState()
{
return (state);
}
public void SetState(int newState)
{
state = newState;
}
}
}
Your help is much appreciated!
Knows where to go everyday.
|
|
|
|
|
Did you use regsvr32 on the com object?
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
it's .NET COM object, so I used "regasm CodeLibrary1.dll /codebase".
There were some little mistakes in namespace and ProgID in my code. So here is the final variant:
using System;
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
[GuidAttribute("1C6CD700-A37B-4295-9CC9-D7392FDD425D"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IFoo
{
[DispId(1)]
string PrintMe();
[DispId(2)]
int ShowState();
[DispId(3)]
void SetState(int newState);
}
[GuidAttribute("C09E2DD6-03EE-4fef-BB84-05D3422DD3D9"),
ClassInterfaceAttribute(ClassInterfaceType.None)]
[ProgIdAttribute("ClassLibrary1.Foo")]
public class Foo : IFoo
{
public Foo() { }
private int state = 100;
public string PrintMe()
{
return ("TEST SUCCESS");
}
public int ShowState()
{
return (state);
}
public void SetState(int newState)
{
state = newState;
}
}
}
Now using CreateObject or New gets the same error: "Run-time error -2147024894 (80070002). File or assembly Classlibrary1, or one of it's dependencies was not found".
|
|
|
|
|
Hi,
I wanna to format any date like SQL Date without changing Regional setting? Where I wanna 2 send a date in a field in sql-server of type date but it changes automatically 2 system format, so I must change regional setting, But I dont like this way
Can Anyone Help me, with a solution?
23DoorsDown
Regards,
Hisham Galal <me4webby@yahoo.com>
|
|
|
|
|
The following function will format a datetime like the old vb dateformat and return a varchar. I use this all the time to format dates in my applications.
/****** Object: UserDefinedFunction [dbo].[udf_FormatDate] Script Date: 07/05/2006 11:11:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create FUNCTION [dbo].[udf_FormatDate] (@date datetime, @format varchar(50))
RETURNS VARCHAR(50) AS
BEGIN
-------------------------------------------------------------------------------------
--
-- Name: FormatDate
--
-- Purpose: Mimics the VB Format routine for dates
--
-- Parameters:
-- @date - Date, Date to be formatted
-- @format - String, Template to format the date to
--
-- Returns: String, Date formatted to user requested template
--
-- Notes:
-- 1. Time information is not accounted for in this routine
--
-- 2. @format accepts the following values for each section of the date.
-- Day
-- dddd - Full Day Name
-- ddd - Abbreviated Day Name
-- dd - Zero Padded Day Number
-- d - Day Number
--
-- Month
-- mmmm - Full Month Name
-- mmm - Abbreviated Month Name
-- mm - Zero Padded Month Number
-- m - Month Number
--
-- Year
-- yyyy - Full 4 digit year
-- yy - 2 digit year
--
-- 3. Any unexpected characters will be returned in the string
--
-- 4. Assumes database was set up with case-insensitive collation
--
-- Example Usage:
-- All examples use the following date 2003-07-13 00:00:00
--
-- 'dddd, mmmm dd, yyyy' --> Sunday, July 13, 2003
-- 'mmddyyyy' --> 07132003
-- 'm-d-yy' --> 7-13-03
-- 'mm/dd/yyyy' --> 07/13/2003
--
-------------------------------------------------------------------------------------
DECLARE @pos AS INTEGER
DECLARE @char AS VARCHAR(1)
--
-- Replace Year
--
SET @pos = CHARINDEX('yyyy', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 4, DATENAME(yyyy, @date))
--PRINT @format
SET @pos = CHARINDEX('yyyy', @format)
END
SET @pos = CHARINDEX('yy', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 2, RIGHT(DATENAME(yyyy, @date) ,2))
--PRINT @format
SET @pos = CHARINDEX('yy', @format)
END
--
-- Replace Month
--
SET @pos = CHARINDEX('mmmm', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 4, DATENAME(month, @date))
--PRINT @format
SET @pos = CHARINDEX('mmmm', @format)
END
SET @pos = CHARINDEX('mmm', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 3, LEFT(DATENAME(month, @date), 3))
--PRINT @format
SET @pos = CHARINDEX('mmm', @format)
END
SET @pos = CHARINDEX('mm', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 2, RIGHT(('0' + CAST(DATEPART(month, @date) AS VARCHAR(2))), 2))
--PRINT @format
SET @pos = CHARINDEX('mm', @format)
END
SET @pos = CHARINDEX('m', @format)
WHILE @pos > 0
BEGIN
-- account for MArch and deceMBer
SET @char = SUBSTRING(@format, @pos + 1, 1)
IF (@char <> 'a') AND (@char <> 'b')
BEGIN
SET @format = STUFF(@format, @pos, 1, CAST(DATEPART(month, @date) AS VARCHAR(2)))
--PRINT @format
SET @pos = CHARINDEX('m', @format)
END
ELSE
BEGIN
SET @pos = CHARINDEX('m', @format, @pos + 1)
END
END
--
-- Replace Day
--
SET @pos = CHARINDEX('dddd', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 4, DATENAME(weekday, @date))
--PRINT @format
SET @pos = CHARINDEX('dddd', @format)
END
SET @pos = CHARINDEX('ddd', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 3, LEFT(DATENAME(weekday, @date), 3))
--PRINT @format
SET @pos = CHARINDEX('ddd', @format)
END
SET @pos = CHARINDEX('dd', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 2, RIGHT(('0' + DATENAME(day, @date)), 2))
--PRINT @format
SET @pos = CHARINDEX('dd', @format)
END
SET @pos = CHARINDEX('d', @format)
WHILE @pos > 0
BEGIN
-- account for DEcember, sunDAy --> saturDAy, weDNesday
SET @char = SUBSTRING(@format, @pos + 1, 1)
IF (@char <> 'e') AND (@char <> 'a') AND (@char <> 'n')
BEGIN
SET @format = STUFF(@format, @pos, 1, CAST(DATEPART(day, @date) AS VARCHAR(2)))
--PRINT @format
SET @pos = CHARINDEX('d', @format)
END
ELSE
BEGIN
SET @pos = CHARINDEX('d', @format, @pos + 1)
END
END
IF @format = '//' BEGIN
SET @format = ''
END
RETURN @format
END
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
|
You could only work with UTC time in your application.
DateTime.UtcNow;
DateTime.ToUniversalTime();
Hope it helps.
All the best,
Martin
|
|
|
|
|
Hi,
I have doubt by using Shadowcopying. Please anyone give samples and explanation how shadow copy is working in .net windows forms using c#.
Thanks,
kokila.
|
|
|
|
|
Shadow copying is a feature of the ASP.NET runtime. It is not used in WinForms because the WinForms compilation model is not dynamic.
Josh
:josh:
My WPF Blog[^]
|
|
|
|
|
WinForms does use ShadowCopy. Actually, the .NET framework itself uses this method also. When an assembly is loaded from the GAC it is really using a shadowcopy, this allows assemblies in the GAC to be updated without the risk of being locked by an application.
Using the AppDomainSetup object you can set the path and whether or not to use shadowcopy when creating a new AppDomain. I have used this method to load assemblies for use in an application and allow them to be updated while the app is running. If the assembly is updated the AppDomain is unloaded and created again there by getting the newer version for use while the app remains active for the user.
|
|
|
|
|
Thanks for the info! I never knew that.
:josh:
My WPF Blog[^]
|
|
|
|
|
Hi,
Thanks for your information. Please i need the sample code which you are using for shadow copying.i have tried the same.But newer version is not updated.
|
|
|
|
|
I have a Windows Form (Form1 is class name) which is the GUI for my app. In Form1 class I have some methods for writing to a textbox. In the same namespace I have another class from which I would like to call Form1's method for writing to that textbox.
Question: How can I call Form1's methods from the another class. I understand how to make calls across classes using instances, but how can I do this when I dont have an instance of Form1 in the other classes? I've tried using static modifiers to Form1's textbox function but that brings up other problems.
So how can I access the Form1's members and methods from another class??
Thanks
|
|
|
|
|
You'd have to find a way to get a reference to the running form. Don't know how you would accomplish that unless the form is instantiating the class in question.
However, what you described sounds like a design choice you should probably reconsider. Instead of having a class that alters a text field, you might want to have that class just take some input and return a string so that any form with a text box can use that functionality.
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
First, although there are other alternatives, in your case it's better for other classes to call Form1 object. Static methods are not a good option here, as you may want to handle multiple Form1 instances.
Second, Form1's data members aren't supposed to be accessed/altered directly by other classes. A better design would be adding Property to Form1. Outsiders access Form1 properties and Form1 binds these properties with its own controls.
Best,
Jun
|
|
|
|
|
Jun Du wrote: A better design would be adding Property to Form1. Outsiders access Form1 properties and Form1 binds these properties with its own controls.
Not much better, a better design would use MVC Pattern.
|
|
|
|
|
Hello alll
I need to find 24 Hrs back DateTime using C#. How to do this.
regards
GV Ramana
regards
GV Ramana
|
|
|
|
|
DateTime back = DateTime.Now.Subtract(new TimeSpan(24, 0, 0));
|
|
|
|
|
May be a little ugly but:
System.DateTime dtYesterday;<br />
dtYesterday = System.DateTime.Now.AddHours(-24);
|
|
|
|
|
Not ugly at all. The method accepts negative values becase you are supposed to use them.
---
b { font-weight: normal; }
|
|
|
|
|
Please don't cross post.
---
b { font-weight: normal; }
|
|
|
|
|
Hello!
When I try to execute a program sometimes it doesn´t work, and if I stop the debug the program that I wanted to be executed initializes =/. It really annoys me!!
What is happening?
Process.Start(ProgrammePfad, AuftragsVerzeichnis);
or
Process p = new Process();<br />
ProcessStartInfo startInfo = new ProcessStartInfo();<br />
startInfo.FileName = ProgrammePfad;
startInfo.Arguments = AuftragsVerzeichnis;
startInfo.ErrorDialog = true;<br />
startInfo.WindowStyle = ProcessWindowStyle.Normal;<br />
<br />
<br />
p.StartInfo = startInfo;<br />
p.Start();
Both of them sometimes work, sometimes don´t! =/
The program that I want to be executed is called InTouch WindowMaker.
Thanks!
Regards
|
|
|
|
|
suguimoto wrote: When I try to execute a program sometimes it doesn´t work,
Are you trying to communicate with the program that you try to execute? If not, what exactly does "it doesn't work" mean?
You could try calling WaitForInputIdle[^] right after starting the process and see if it helps.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|