Giter Site home page Giter Site logo

Add wincred.h about win32 HOT 10 CLOSED

hpoul avatar hpoul commented on August 20, 2024
Add wincred.h

from win32.

Comments (10)

domesticmouse avatar domesticmouse commented on August 20, 2024

Hey @hpoul,

I think you will find @timsneath's answer in #64 (comment) helpful on the autogeneration / hand coding front.

Do you have an idea of which specific API calls you want to make?

from win32.

hpoul avatar hpoul commented on August 20, 2024

@domesticmouse thanks for your fast reply, i think right now it's CredWrite, CredRead, CredDelete. I don't have experience with win32 APIs (yet), but those seem to be the closest to keychain read/write/delete :)

not sure if it's better to have a generic ffi bridge, or just use the specific C functions in my library (which is how i've implemented it for linux right now), but if it's easier to build on this package, it would be great ;-)

from win32.

timsneath avatar timsneath commented on August 20, 2024

Yeah, easy enough to add those functions, and they seem useful to others also. I'll put a quick pull request together.

As far as the latter question is concerned, you're obviously welcome to do what works best for you. But three reasons why you might consider a direct dependency on win32:

  • With Dart tree shaking, you're not paying any additional 'tax' for the parts of win32 you're not using; only those typedefs that you actually use are compiled into your plugin;
  • Obviously any improvements made to the Win32 package come for free (e.g. Dart finalizer support, or improvements to struct layout, when they arrive)
  • If you ever choose to expose any of the credentials outside of your own package, it might be helpful if the Structs etc. are in a common package.

from win32.

hpoul avatar hpoul commented on August 20, 2024

cool thanks, that would be great.

To be honest my question was actually if it would be easier for me to work out how to add those APIs to win32 and make a PR vs. just doing it in my own plugin. If I just have to use the package, I'll certainly go for it 😅️

from win32.

timsneath avatar timsneath commented on August 20, 2024

You are very welcome to do so, if you want to get familiar with these APIs. A couple of tips:

If you don't feel comfortable with doing this work, let me know; happy to investigate it at some point.

from win32.

domesticmouse avatar domesticmouse commented on August 20, 2024

@timsneath Can we promote your comment to a section in either the README? Seems like a useful getting started guide.

from win32.

timsneath avatar timsneath commented on August 20, 2024

Done: https://github.com/timsneath/win32/blob/master/CONTRIBUTING.md

from win32.

hpoul avatar hpoul commented on August 20, 2024

Thanks for the hints.. I've started adding the functions/structs and CredWrite seems to work as I can see the written credential in the Credential Manager, but CredRead returns success without filling my credential struct.
Do you have any idea what I could be doing wrong? I allocate a Pointer and pass it into the function, do I need to do something else to pass it by reference?

https://github.com/authpass/win32/blob/wincred/example/credentials.dart#L35-L43

  final cred = CREDENTIAL.allocate();
  final result = CredRead(
      TEXT(credentialName), CRED_TYPE_GENERIC, 0, cred.addressOf);
  if (result != TRUE) {
    final errorCode = GetLastError();
    print('Error ($result): $errorCode');
    return;
  }
  print('Success. size: ${cred.CredentialBlobSize}');

outputs:

Success. size: 0

(Even though I've written 10 bytes, which I can see in the Credential Manager)

from win32.

hpoul avatar hpoul commented on August 20, 2024

never mind, I somehow missed that it was PCREDENTIAL not CREDENTIAL. 🤦️ ie. I had to use Pointer<Pointer<CREDENTIAL>>

from win32.

timsneath avatar timsneath commented on August 20, 2024

Ah yes -- they're sneaky with that. The second * is masked in the typedef, so PCREDENTIAL *x is equivalent to CREDENTIAL **x. I spent days blocked on a similar issue when I built out the COM support, so the fact that you'd figured it out before I'd even looked at the code is something you can feel good about :)

from win32.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.