Archive for December, 2008

Programmatically transcode MPEG-2 videos

Read the original question at Recent Questions - Stack Overflow.

Leave a Comment

Using an enum as an array index

I have this enum:

enum ButtonState {
    BUTTON_NORMAL = 0,
    BUTTON_PRESSED = 1,
    BUTTON_CLICKED = 2
};

const u8 NUM_BUTTON_STATES = 3;

In my Button class I have member variables ButtonState state; and ButtonColors colors[NUM_BUTTON_STATES];. When drawing the button, I use colors[state] to get the colours for whatever state the button is in.

My questions:

  1. Is this good programming style? Is there a better way to do it? (I usually only use enums with switch statements... using an enum as an array index doesn't feel right.)
  2. Do I have to specify the values of the enum? It seems to start from 0 by default and increment by 1 but is it guaranteed to work that way in all compilers?

Read the original question at Top Questions - Stack Overflow.

Leave a Comment

How can you add pictures to an Outlook 2007 message in actual pixel size? [closed]

When I add pictures to a HTML mail message in Outlook 2007, they are automatically scaled, and quality-wise they look pretty bad.

How can I make Outlook display the pictures correctly, without transforming them? And if that isn't possible, what is a better way to email photos to friends and family?

Read the original question at Top Questions - Stack Overflow.

Leave a Comment

Does C# .NET support IDispatch late binding?


The Question

My question is: Does C# nativly support late-binding IDispatch?


Pretend i'm trying to automate Office, while being compatible with whatever version the customer has installed.

In the .NET world if you developed with Office 2000 installed, every developer, and every customer, from now until the end of time, is required to have Office 2000.

In the world before .NET, we used COM to talk to Office applications.

For example:

1) Use the version independant ProgID

"Excel.Application"

which resolves to:

clsid = {00024500-0000-0000-C000-000000000046}

and then using COM, we ask for one of these classes to be instantiated into an object:

IUnknown unk;
CoCreateInstance(
    clsid, 
    null,
    CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
    IUnknown, 
    out unk);

And now we're off to the races - able to use Excel from inside my application. Of course, if really you want to use the object, you have to call have some way of calling methods.

We could get ahold of the various interface declarations, translated into our language. This technique is good because we get

  • early binding
  • code-insight
  • compile type syntax checking

and some example code might be:

Application xl = (IExcelApplication)unk;
ExcelWorkbook workbook = xl.Workbooks.Add(template, lcid);
Worksheet worksheet = workbook.ActiveSheet;


But there is a downside of using interfaces: we have to get ahold of the various interface declarations, transated into our language. And we're stuck using method-based invocations, having to specify all parameters, e.g.:

ExcelWorkbook workbook = xl.Workbooks.Add(template, lcid);
xl.Worksheets.Add(before, after, count, type, lcid);

This has proved, in the real world, to have such downsides that willingly give up:

  • early binding
  • code-insight
  • compile time syntax checking

and instead use IDispatch late binding:

Variant xl = (IDispatch)unk;
Variant newWorksheet = xl.Worksheets.Add();

Because Excel automation was designed for VB Script, a lot of parameters can be ommitted, even when there is no overload without them.

Note: Don't confuse my example of Excel with a reason of why i want to use IDispatch. Not every COM object is Excel. Some COM objects have no support other than through IDispatch.

Read the original question at Top Questions - Stack Overflow.

Leave a Comment

creating a substring on Linux IA-32 assembler (gas)

I wanna create a substring (ministring) of 3 asciz chars out of my original (thestring). The thing ain't printing when being run so I don't know what the hell I'm I doing. Why it ain't printing? Am I creating the ministring correctly?

.section .data

thestring: .asciz "111010101"

ministring: .asciz ""

formatd:    .asciz "%d"
formats:    .asciz "%s"
formatc:    .asciz "%c"




.section .text

.globl _start

_start:

xorl %ecx, %ecx

ciclo:movb thestring(%ecx,1), %al
movzbl %al, %eax
movl %eax, ministring(%ecx,1)
incl %ecx
cmpl $3, %ecx
jl ciclo


movl thestring, %eax
pushl %eax
pushl $formats
call printf
addl $4, %esp


movl $1, %eax
movl $0, %ebx
int $0x80

Read the original question at Top Questions - Stack Overflow.

Leave a Comment

Circle-Rectangle collision detection (intersection)

How can I tell whether a circle and a rectangle intersect in 2D Euclidean space? (i.e. classic 2D geometry)

Read the original question at Top Questions - Stack Overflow.

Leave a Comment

Xcode: iPhone app codesign error

Read the original question at Recent Questions - Stack Overflow.

Leave a Comment

Ordering admin.ModelAdmin objects in Django Admin

Read the original question at Recent Questions - Stack Overflow.

Leave a Comment

ASP.NET: Web Site or Web Application?

When I start a new ASP.NET project in Visual Studio 2008, I can either create a new ASP.NET Web Site or an ASP.NET Web Application.

What's the difference between these two project types? Why would I choose one over the other?

If I'm using Visual Studio 2005 instead of Visual Studio 2008, is the answer different?

Read the original question at Top Questions - Stack Overflow.

Leave a Comment

Is Web Browser “Discrimination” Okay?

Read the original question at Recent Questions - Stack Overflow.

Leave a Comment