|
Actually, try removing the out keyword from the last parameter declaration of GetIDsOfNames since an int[] array is already a reference type. The caller (you) must also allocate the array, so try int[] rgDispId = new int[1]; instead of creating an empty array.
This is definitely the right track, though I've never tried using the dispatch interface in managed code like this.
Another way would be to call IDispatch.GetTypeInfo and use the UCOMITypeInfo interface (which is fortunately defined in the FCL so you don't have to declare it) and use it's member methods to basically do the same thing.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Still get the same error. rgDispId isn't set to null anymore but contains 0, or what ever value I put in it to start with. It must be failing in the GetIDsOfNames method before it gets to assign anything.
Does this have anything to do with OleInitialize and CoCreateInstance . I thought Word.Application MSWord = new Word.ApplicationClass(); called these behind the scenes.
Also
IDispatch wb = (IDispatch)MSWord.WordBasic;
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID
UCOMITypeInfo tpInf = (UCOMITypeInfo)wb.GetTypeInfo(0, lcid);
Throws the exception No such interface supported .
However
IDispatch ms = (IDispatch)MSWord;
int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID
UCOMITypeInfo tpInf = (UCOMITypeInfo)ms.GetTypeInfo(0, lcid);
doesn't. Can I get at it this way?
|
|
|
|
|
ComInitialize is called behind the scenes by the CLR, and you already have an instance of the WordBasic object so long as it isn't null. The fact that you're getting the IDispatch reference when you cast - for which the CLR performs a QueryInterface - shows that it supports automation, so I'm surprised that GetTypeInfo fails.
At this point, I would recommend going to the Word newsgroup (NNTP news server is msnews.microsoft.com) and seeing if there is another way to disable macros on startup.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Will do. I have a feeling it isn't possible mind
Thanks for all the help, I've learned a great deal this last few days.
|
|
|
|
|
Got it working!!
Needed a few changes to the interface thats all.
[Guid("00020400-0000-0000-c000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDispatch
{
[PreserveSig] int GetTypeInfoCount();
UCOMITypeInfo GetTypeInfo(
[MarshalAs(UnmanagedType.U4)] int iTInfo,
[MarshalAs(UnmanagedType.U4)] int lcid);
[PreserveSig] int GetIDsOfNames(
ref Guid riid,
[MarshalAs(UnmanagedType.LPArray,
ArraySubType=UnmanagedType.LPWStr)]
string[] rgsNames,
int cNames,
int lcid,
[MarshalAs(UnmanagedType.LPArray)] int[] rgDispId);
[PreserveSig] int Invoke(
int dispIdMember,
ref Guid riid,
[MarshalAs(UnmanagedType.U4)] int lcid,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
ref DISPPARAMS pDispParams,
[MarshalAs(UnmanagedType.LPArray)][Out] object[] pVarResult,
ref EXCEPINFO pExcepInfo,
[MarshalAs(UnmanagedType.LPArray)][Out] IntPtr[] pArgErr);
}
Thanks again.
|
|
|
|
|
Glad you got it working, but I find this interesting since the declaration I gave you was pulled out of the .NET FCL assemblies (written by Microsoft). Oh well, whatever works, right?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I need to get a list of computers which are currently logged on a local area network. I can get the server ip by using DNS (API). However, I can not figure out how to get the list of computer . Please help me to figure out this problem.
Thanks,
Nemo
|
|
|
|
|
This has been covered many times in the past. Please click on "Search comments" directly above this message board and search for previous discussions.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
:(I have tried to search for the similar articles but i can not find any...
Nemo
|
|
|
|
|
|
I need to work out week numbers for a given date starting from 1 jan as week 1, so when a user inouts a date i need to work out what week number we are in please
|
|
|
|
|
See the documentation for DateTime structure. It's properties and methods can give you all the infos you need, e.g. DayOfWeek or DayOfYear properties. The rest some simple mathematics you can surely figure out yourself
|
|
|
|
|
yes i was aware of that, your right i was being lazy i was hoping someone may have a formula alreadt sorted cant life be that simple?
|
|
|
|
|
Sometimes it is, but obviously not today
|
|
|
|
|
robmays wrote:
I was hoping someone may have a formula already sorted
What you mean: DayOfYear / 7
robmays wrote:
I was being lazy
It sure looks like it from here.
robmays wrote:
can't life be that simple?
"Life is tough, but if you're tough on yourself, then life is so much easier on YOU!" -- Zig Ziglar
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
no not that one bit mor complicated here is one for someone if needed
// Static Method to return WeekNumber (1-53) for a given year
public static int WeekNumber(DateTime dt) {
// Set Year
int yyyy=dt.Year;
// Set Month
int mm=dt.Month;
// Set Day
int dd=dt.Day;
// Declare other required variables
int DayOfYearNumber;
int Jan1WeekDay;
int WeekNumber=0, WeekDay;
int i,j,k,l,m,n;
int[] Mnth = new int[12] {0,31,59,90,120,151,181,212,243,273,304,334};
int YearNumber;
// Set DayofYear Number for yyyy mm dd
DayOfYearNumber = dd + Mnth[mm-1];
// Increase of Dayof Year Number by 1, if year is leapyear and month is february
if ((IsLeapYear(yyyy) == true) && (mm == 2))
DayOfYearNumber += 1;
// Find the Jan1WeekDay for year
i = (yyyy - 1) % 100;
j = (yyyy - 1) - i;
k = i + i/4;
Jan1WeekDay = 1 + (((((j / 100) % 4) * 5) + k) % 7);
// Calcuate the WeekDay for the given date
l= DayOfYearNumber + (Jan1WeekDay - 1);
WeekDay = 1 + ((l - 1) % 7);
// Find if the date falls in YearNumber set WeekNumber to 52 or 53
if ((DayOfYearNumber <= (8 - Jan1WeekDay)) && (Jan1WeekDay > 4))
{
YearNumber = yyyy - 1;
if ((Jan1WeekDay == 5) || ((Jan1WeekDay == 6) && (Jan1WeekDay > 4)))
WeekNumber = 53;
else
WeekNumber = 52;
}
else
YearNumber = yyyy;
// Set WeekNumber to 1 to 53 if date falls in YearNumber
if (YearNumber == yyyy)
{
if (IsLeapYear(yyyy)==true)
m = 366;
else
m = 365;
if ((m - DayOfYearNumber) < (4-WeekDay))
{
YearNumber = yyyy + 1;
WeekNumber = 1;
}
}
if (YearNumber==yyyy) {
n=DayOfYearNumber + (7 - WeekDay) + (Jan1WeekDay -1);
WeekNumber = n / 7;
if (Jan1WeekDay > 4)
WeekNumber -= 1;
}
return (WeekNumber);
}
|
|
|
|
|
Nice work, but why don't you use properties of the structure DateTime? Some of them i even mentioned in my first comment. I think this could at least spare you some lines of code and therefor increase readibility.
For example you wrote:
DayOfYearNumber = dd + Mnth[mm-1];<br />
<br />
l= DayOfYearNumber + (Jan1WeekDay - 1);<br />
WeekDay = 1 + ((l - 1) % 7);
Alternativ:
DayOfYearNumber = dt.DayOfYear;<br />
<br />
l = dt.DayOfWeek;
|
|
|
|
|
robmays wrote:
// Set DayofYear Number for yyyy mm dd
DayOfYearNumber = dd + Mnth[mm-1];
// Increase of Dayof Year Number by 1, if year is leapyear and month is february
if ((IsLeapYear(yyyy) == true) && (mm == 2))
DayOfYearNumber += 1;
The result of this calculation will be wrong for any date from the 1st February onwards on a leap year. You will increase the DayOfYearNumber on a leap year if the month is February (before the leap day occurs), but not for the remainder of the months in the year (after the leap day).
try:
if ((IsLeapYear(yyyy)) && (mm > 2))
DayOfYearNumber++;
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
Why don't you use System.Globalization.GregorianCalendar object which has GetWeekOfYear method : -
public static int WeekNumber(DateTime dt)
{
System.Globalization.GregorianCalendar gCal=new System.Globalization.GregorianCalendar();
return gCal.GetWeekOfYear(dt,System.Globalization.CalendarWeekRule.FirstDay,System.DayOfWeek.Monday);
}
Cheers
Never comment ur code. If it was hard to write, it should be hard to understand !!!
|
|
|
|
|
Life can be so simple.
The framework has a method for almost everything, you just need to find it
|
|
|
|
|
well since i have been too lunch i think i have had my 5 min of fame, glad to have stirred a few pro developers, i am a newbee like the look of the globalization near the end i will look into that one BUT in the ned i got my easy life so as i concentrate on the bigger picture.;);)
|
|
|
|
|
robmays wrote:
i have had my 5 min of fame
Well, according to Andy Worhole you get another 10 minutes.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
There's no good excuse for not reading the .NET Framework SDK documentation. Reading documentation is one thing that separates the developers from the code monkeys.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok ,ive started on my page class so you know what my weekend will be like. i ve started by adding a new class to the project called pgeHeating:TabPage is that correct so far with the inheritance
|
|
|
|
|
Yes, but use the .NET naming conventions. Keeping with the naming conventions is important to maintain a common convention through an application and the Framework. A better name would be something like HeatingPage . Just look at how the classes and members are named throughout the .NET FCL.
Microsoft MVP, Visual C#
My Articles
|
|
|
|